annotate src/share/vm/classfile/verifier.hpp @ 20242:d14a18794c90

8051012: Regression in verifier for <init> method call from inside of a branch Summary: Fix stackmap matching for branches. Reviewed-by: coleenp, lfoltan, acorn
author hseigel
date Sat, 02 Aug 2014 16:28:59 -0400
parents f73af4455d7d
children 077483254bf6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 13401
diff changeset
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 973
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 973
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 973
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
25 #ifndef SHARE_VM_CLASSFILE_VERIFIER_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
26 #define SHARE_VM_CLASSFILE_VERIFIER_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
28 #include "classfile/verificationType.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
29 #include "memory/gcLocker.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
30 #include "oops/klass.hpp"
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6605
diff changeset
31 #include "oops/method.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
32 #include "runtime/handles.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
33 #include "utilities/exceptions.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
34
0
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // The verifier class
a61af66fc99e Initial load
duke
parents:
diff changeset
36 class Verifier : AllStatic {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 public:
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
38 enum {
10381
4552a7633a07 8015385: Remove RelaxAccessControlCheck for JDK 8 bytecodes
hseigel
parents: 10265
diff changeset
39 STRICTER_ACCESS_CTRL_CHECK_VERSION = 49,
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
40 STACKMAP_ATTRIBUTE_MAJOR_VERSION = 50,
10381
4552a7633a07 8015385: Remove RelaxAccessControlCheck for JDK 8 bytecodes
hseigel
parents: 10265
diff changeset
41 INVOKEDYNAMIC_MAJOR_VERSION = 51,
4552a7633a07 8015385: Remove RelaxAccessControlCheck for JDK 8 bytecodes
hseigel
parents: 10265
diff changeset
42 NO_RELAX_ACCESS_CTRL_CHECK_VERSION = 52
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
43 };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
44 typedef enum { ThrowException, NoException } Mode;
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
47 * Verify the bytecodes for a class. If 'throw_exception' is true
a61af66fc99e Initial load
duke
parents:
diff changeset
48 * then the appropriate VerifyError or ClassFormatError will be thrown.
a61af66fc99e Initial load
duke
parents:
diff changeset
49 * Otherwise, no exception is thrown and the return indicates the
a61af66fc99e Initial load
duke
parents:
diff changeset
50 * error.
a61af66fc99e Initial load
duke
parents:
diff changeset
51 */
973
ad6585fd4087 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 0
diff changeset
52 static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
53
973
ad6585fd4087 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 0
diff changeset
54 // Return false if the class is loaded by the bootstrap loader,
ad6585fd4087 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 0
diff changeset
55 // or if defineClass was called requesting skipping verification
ad6585fd4087 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 0
diff changeset
56 // -Xverify:all/none override this value
ad6585fd4087 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 0
diff changeset
57 static bool should_verify_for(oop class_loader, bool should_verify_class);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // Relax certain verifier checks to enable some broken 1.1 apps to run on 1.2.
a61af66fc99e Initial load
duke
parents:
diff changeset
60 static bool relax_verify_for(oop class_loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private:
973
ad6585fd4087 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 0
diff changeset
63 static bool is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class);
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
64 static Symbol* inference_verify(
0
a61af66fc99e Initial load
duke
parents:
diff changeset
65 instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
66 };
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 class RawBytecodeStream;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 class StackMapFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 class StackMapTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // Summary of verifier's memory usage:
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // StackMapTable is stack allocated.
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
74 // StackMapFrame are resource allocated. There is only one ResourceMark
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
75 // for each class verification, which is created at the top level.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // There is one mutable StackMapFrame (current_frame) which is updated
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // by abstract bytecode interpretation. frame_in_exception_handler() returns
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // a frame that has a mutable one-item stack (ready for pushing the
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // catch type exception object). All the other StackMapFrame's
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // are immutable (including their locals and stack arrays) after
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // their constructions.
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // locals/stack arrays in StackMapFrame are resource allocated.
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // locals/stack arrays can be shared between StackMapFrame's, except
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // the mutable StackMapFrame (current_frame).
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // These macros are used similarly to CHECK macros but also check
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // the status of the verifier and return if that has an error.
a61af66fc99e Initial load
duke
parents:
diff changeset
88 #define CHECK_VERIFY(verifier) \
10973
ef57c43512d6 8014431: cleanup warnings indicated by the -Wunused-value compiler option on linux
ccheung
parents: 10381
diff changeset
89 CHECK); if ((verifier)->has_error()) return; ((void)0
0
a61af66fc99e Initial load
duke
parents:
diff changeset
90 #define CHECK_VERIFY_(verifier, result) \
10973
ef57c43512d6 8014431: cleanup warnings indicated by the -Wunused-value compiler option on linux
ccheung
parents: 10381
diff changeset
91 CHECK_(result)); if ((verifier)->has_error()) return (result); ((void)0
0
a61af66fc99e Initial load
duke
parents:
diff changeset
92
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
93 class TypeOrigin VALUE_OBJ_CLASS_SPEC {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
94 private:
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
95 typedef enum {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
96 CF_LOCALS, // Comes from the current frame locals
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
97 CF_STACK, // Comes from the current frame expression stack
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
98 SM_LOCALS, // Comes from stackmap locals
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
99 SM_STACK, // Comes from stackmap expression stack
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
100 CONST_POOL, // Comes from the constant pool
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
101 SIG, // Comes from method signature
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
102 IMPLICIT, // Comes implicitly from code or context
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
103 BAD_INDEX, // No type, but the index is bad
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
104 FRAME_ONLY, // No type, context just contains the frame
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
105 NONE
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
106 } Origin;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
107
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
108 Origin _origin;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
109 u2 _index; // local, stack, or constant pool index
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
110 StackMapFrame* _frame; // source frame if CF or SM
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
111 VerificationType _type; // The actual type
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
112
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
113 TypeOrigin(
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
114 Origin origin, u2 index, StackMapFrame* frame, VerificationType type)
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
115 : _origin(origin), _index(index), _frame(frame), _type(type) {}
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
116
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
117 public:
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
118 TypeOrigin() : _origin(NONE), _index(0), _frame(NULL) {}
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
119
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
120 static TypeOrigin null();
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
121 static TypeOrigin local(u2 index, StackMapFrame* frame);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
122 static TypeOrigin stack(u2 index, StackMapFrame* frame);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
123 static TypeOrigin sm_local(u2 index, StackMapFrame* frame);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
124 static TypeOrigin sm_stack(u2 index, StackMapFrame* frame);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
125 static TypeOrigin cp(u2 index, VerificationType vt);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
126 static TypeOrigin signature(VerificationType vt);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
127 static TypeOrigin bad_index(u2 index);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
128 static TypeOrigin implicit(VerificationType t);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
129 static TypeOrigin frame(StackMapFrame* frame);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
130
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
131 void reset_frame();
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
132 void details(outputStream* ss) const;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
133 void print_frame(outputStream* ss) const;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
134 const StackMapFrame* frame() const { return _frame; }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
135 bool is_valid() const { return _origin != NONE; }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
136 u2 index() const { return _index; }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
137
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
138 #ifdef ASSERT
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
139 void print_on(outputStream* str) const;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
140 #endif
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
141 };
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
142
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
143 class ErrorContext VALUE_OBJ_CLASS_SPEC {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
144 private:
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
145 typedef enum {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
146 INVALID_BYTECODE, // There was a problem with the bytecode
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
147 WRONG_TYPE, // Type value was not as expected
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
148 FLAGS_MISMATCH, // Frame flags are not assignable
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
149 BAD_CP_INDEX, // Invalid constant pool index
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
150 BAD_LOCAL_INDEX, // Invalid local index
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
151 LOCALS_SIZE_MISMATCH, // Frames have differing local counts
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
152 STACK_SIZE_MISMATCH, // Frames have different stack sizes
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
153 STACK_OVERFLOW, // Attempt to push onto a full expression stack
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
154 STACK_UNDERFLOW, // Attempt to pop and empty expression stack
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
155 MISSING_STACKMAP, // No stackmap for this location and there should be
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
156 BAD_STACKMAP, // Format error in stackmap
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
157 NO_FAULT, // No error
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
158 UNKNOWN
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
159 } FaultType;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
160
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
161 int _bci;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
162 FaultType _fault;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
163 TypeOrigin _type;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
164 TypeOrigin _expected;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
165
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
166 ErrorContext(int bci, FaultType fault) :
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
167 _bci(bci), _fault(fault) {}
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
168 ErrorContext(int bci, FaultType fault, TypeOrigin type) :
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
169 _bci(bci), _fault(fault), _type(type) {}
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
170 ErrorContext(int bci, FaultType fault, TypeOrigin type, TypeOrigin exp) :
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
171 _bci(bci), _fault(fault), _type(type), _expected(exp) {}
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
172
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
173 public:
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
174 ErrorContext() : _bci(-1), _fault(NO_FAULT) {}
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
175
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
176 static ErrorContext bad_code(u2 bci) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
177 return ErrorContext(bci, INVALID_BYTECODE);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
178 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
179 static ErrorContext bad_type(u2 bci, TypeOrigin type) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
180 return ErrorContext(bci, WRONG_TYPE, type);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
181 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
182 static ErrorContext bad_type(u2 bci, TypeOrigin type, TypeOrigin exp) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
183 return ErrorContext(bci, WRONG_TYPE, type, exp);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
184 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
185 static ErrorContext bad_flags(u2 bci, StackMapFrame* frame) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
186 return ErrorContext(bci, FLAGS_MISMATCH, TypeOrigin::frame(frame));
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
187 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
188 static ErrorContext bad_flags(u2 bci, StackMapFrame* cur, StackMapFrame* sm) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
189 return ErrorContext(bci, FLAGS_MISMATCH,
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
190 TypeOrigin::frame(cur), TypeOrigin::frame(sm));
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
191 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
192 static ErrorContext bad_cp_index(u2 bci, u2 index) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
193 return ErrorContext(bci, BAD_CP_INDEX, TypeOrigin::bad_index(index));
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
194 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
195 static ErrorContext bad_local_index(u2 bci, u2 index) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
196 return ErrorContext(bci, BAD_LOCAL_INDEX, TypeOrigin::bad_index(index));
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
197 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
198 static ErrorContext locals_size_mismatch(
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
199 u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
200 return ErrorContext(bci, LOCALS_SIZE_MISMATCH,
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
201 TypeOrigin::frame(frame0), TypeOrigin::frame(frame1));
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
202 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
203 static ErrorContext stack_size_mismatch(
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
204 u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
205 return ErrorContext(bci, STACK_SIZE_MISMATCH,
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
206 TypeOrigin::frame(frame0), TypeOrigin::frame(frame1));
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
207 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
208 static ErrorContext stack_overflow(u2 bci, StackMapFrame* frame) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
209 return ErrorContext(bci, STACK_OVERFLOW, TypeOrigin::frame(frame));
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
210 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
211 static ErrorContext stack_underflow(u2 bci, StackMapFrame* frame) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
212 return ErrorContext(bci, STACK_UNDERFLOW, TypeOrigin::frame(frame));
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
213 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
214 static ErrorContext missing_stackmap(u2 bci) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
215 return ErrorContext(bci, MISSING_STACKMAP);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
216 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
217 static ErrorContext bad_stackmap(int index, StackMapFrame* frame) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
218 return ErrorContext(0, BAD_STACKMAP, TypeOrigin::frame(frame));
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
219 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
220
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
221 bool is_valid() const { return _fault != NO_FAULT; }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
222 int bci() const { return _bci; }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
223
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
224 void reset_frames() {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
225 _type.reset_frame();
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
226 _expected.reset_frame();
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
227 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
228
10265
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 6725
diff changeset
229 void details(outputStream* ss, const Method* method) const;
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
230
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
231 #ifdef ASSERT
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
232 void print_on(outputStream* str) const {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
233 str->print("error_context(%d, %d,", _bci, _fault);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
234 _type.print_on(str);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
235 str->print(",");
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
236 _expected.print_on(str);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
237 str->print(")");
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
238 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
239 #endif
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
240
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
241 private:
10265
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 6725
diff changeset
242 void location_details(outputStream* ss, const Method* method) const;
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
243 void reason_details(outputStream* ss) const;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
244 void frame_details(outputStream* ss) const;
10265
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 6725
diff changeset
245 void bytecode_details(outputStream* ss, const Method* method) const;
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 6725
diff changeset
246 void handler_details(outputStream* ss, const Method* method) const;
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 6725
diff changeset
247 void stackmap_details(outputStream* ss, const Method* method) const;
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
248 };
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
249
0
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // A new instance of this class is created for each class being verified
a61af66fc99e Initial load
duke
parents:
diff changeset
251 class ClassVerifier : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
252 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
253 Thread* _thread;
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
254 GrowableArray<Symbol*>* _symbols; // keep a list of symbols created
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
255
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
256 Symbol* _exception_type;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
257 char* _message;
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
258
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
259 ErrorContext _error_context; // contains information about an error
0
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 void verify_method(methodHandle method, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
262 char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
263 void verify_exception_handler_table(u4 code_length, char* code_data,
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
264 int& min, int& max, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
265 void verify_local_variable_table(u4 code_length, char* code_data, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 VerificationType cp_ref_index_to_type(
a61af66fc99e Initial load
duke
parents:
diff changeset
268 int index, constantPoolHandle cp, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 bool is_protected_access(
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6605
diff changeset
273 instanceKlassHandle this_class, Klass* target_class,
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
274 Symbol* field_name, Symbol* field_sig, bool is_method);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
275
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
276 void verify_cp_index(u2 bci, constantPoolHandle cp, int index, TRAPS);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
277 void verify_cp_type(u2 bci, int index, constantPoolHandle cp,
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
278 unsigned int types, TRAPS);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
279 void verify_cp_class_type(u2 bci, int index, constantPoolHandle cp, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 u2 verify_stackmap_table(
a61af66fc99e Initial load
duke
parents:
diff changeset
282 u2 stackmap_index, u2 bci, StackMapFrame* current_frame,
a61af66fc99e Initial load
duke
parents:
diff changeset
283 StackMapTable* stackmap_table, bool no_control_flow, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 void verify_exception_handler_targets(
a61af66fc99e Initial load
duke
parents:
diff changeset
286 u2 bci, bool this_uninit, StackMapFrame* current_frame,
a61af66fc99e Initial load
duke
parents:
diff changeset
287 StackMapTable* stackmap_table, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 void verify_ldc(
a61af66fc99e Initial load
duke
parents:
diff changeset
290 int opcode, u2 index, StackMapFrame *current_frame,
a61af66fc99e Initial load
duke
parents:
diff changeset
291 constantPoolHandle cp, u2 bci, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293 void verify_switch(
a61af66fc99e Initial load
duke
parents:
diff changeset
294 RawBytecodeStream* bcs, u4 code_length, char* code_data,
a61af66fc99e Initial load
duke
parents:
diff changeset
295 StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 void verify_field_instructions(
a61af66fc99e Initial load
duke
parents:
diff changeset
298 RawBytecodeStream* bcs, StackMapFrame* current_frame,
a61af66fc99e Initial load
duke
parents:
diff changeset
299 constantPoolHandle cp, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 void verify_invoke_init(
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
302 RawBytecodeStream* bcs, u2 ref_index, VerificationType ref_class_type,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
303 StackMapFrame* current_frame, u4 code_length, bool* this_uninit,
a61af66fc99e Initial load
duke
parents:
diff changeset
304 constantPoolHandle cp, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 void verify_invoke_instructions(
a61af66fc99e Initial load
duke
parents:
diff changeset
307 RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
a61af66fc99e Initial load
duke
parents:
diff changeset
308 bool* this_uninit, VerificationType return_type,
a61af66fc99e Initial load
duke
parents:
diff changeset
309 constantPoolHandle cp, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
310
a61af66fc99e Initial load
duke
parents:
diff changeset
311 VerificationType get_newarray_type(u2 index, u2 bci, TRAPS);
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
312 void verify_anewarray(u2 bci, u2 index, constantPoolHandle cp,
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
313 StackMapFrame* current_frame, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
314 void verify_return_value(
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
315 VerificationType return_type, VerificationType type, u2 offset,
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
316 StackMapFrame* current_frame, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 void verify_iload (u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 void verify_lload (u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
320 void verify_fload (u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
321 void verify_dload (u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
322 void verify_aload (u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
323 void verify_istore(u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
324 void verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
326 void verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
328 void verify_iinc (u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
329
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
330 bool name_in_supers(Symbol* ref_name, instanceKlassHandle current);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
331
1955
1070423b51f3 6865028: Illegal instructions passing verification prior to 'invokespecial Object.<init>'
kamg
parents: 1602
diff changeset
332 VerificationType object_type() const;
1070423b51f3 6865028: Illegal instructions passing verification prior to 'invokespecial Object.<init>'
kamg
parents: 1602
diff changeset
333
0
a61af66fc99e Initial load
duke
parents:
diff changeset
334 instanceKlassHandle _klass; // the class being verified
a61af66fc99e Initial load
duke
parents:
diff changeset
335 methodHandle _method; // current method being verified
a61af66fc99e Initial load
duke
parents:
diff changeset
336 VerificationType _this_type; // the verification type of the current class
a61af66fc99e Initial load
duke
parents:
diff changeset
337
1570
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
338 // Some recursive calls from the verifier to the name resolver
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
339 // can cause the current class to be re-verified and rewritten.
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
340 // If this happens, the original verification should not continue,
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
341 // because constant pool indexes will have changed.
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
342 // The rewriter is preceded by the verifier. If the verifier throws
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
343 // an error, rewriting is prevented. Also, rewriting always precedes
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
344 // bytecode execution or compilation. Thus, is_rewritten implies
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
345 // that a class has been verified and prepared for execution.
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
346 bool was_recursively_verified() { return _klass->is_rewritten(); }
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
347
13401
22eaa15b7960 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 10973
diff changeset
348 bool is_same_or_direct_interface(instanceKlassHandle klass,
22eaa15b7960 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 10973
diff changeset
349 VerificationType klass_type, VerificationType ref_class_type);
22eaa15b7960 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 10973
diff changeset
350
0
a61af66fc99e Initial load
duke
parents:
diff changeset
351 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
352 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 BYTECODE_OFFSET = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
354 NEW_OFFSET = 2
a61af66fc99e Initial load
duke
parents:
diff changeset
355 };
a61af66fc99e Initial load
duke
parents:
diff changeset
356
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // constructor
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
358 ClassVerifier(instanceKlassHandle klass, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 // destructor
a61af66fc99e Initial load
duke
parents:
diff changeset
361 ~ClassVerifier();
a61af66fc99e Initial load
duke
parents:
diff changeset
362
a61af66fc99e Initial load
duke
parents:
diff changeset
363 Thread* thread() { return _thread; }
a61af66fc99e Initial load
duke
parents:
diff changeset
364 methodHandle method() { return _method; }
a61af66fc99e Initial load
duke
parents:
diff changeset
365 instanceKlassHandle current_class() const { return _klass; }
a61af66fc99e Initial load
duke
parents:
diff changeset
366 VerificationType current_type() const { return _this_type; }
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // Verifies the class. If a verify or class file format error occurs,
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // the '_exception_name' symbols will set to the exception name and
a61af66fc99e Initial load
duke
parents:
diff changeset
370 // the message_buffer will be filled in with the exception message.
a61af66fc99e Initial load
duke
parents:
diff changeset
371 void verify_class(TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
372
a61af66fc99e Initial load
duke
parents:
diff changeset
373 // Return status modes
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
374 Symbol* result() const { return _exception_type; }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
375 bool has_error() const { return result() != NULL; }
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
376 char* exception_message() {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
377 stringStream ss;
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 13401
diff changeset
378 ss.print("%s", _message);
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
379 _error_context.details(&ss, _method());
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
380 return ss.as_string();
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
381 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
382
a61af66fc99e Initial load
duke
parents:
diff changeset
383 // Called when verify or class format errors are encountered.
a61af66fc99e Initial load
duke
parents:
diff changeset
384 // May throw an exception based upon the mode.
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 13401
diff changeset
385 void verify_error(ErrorContext ctx, const char* fmt, ...) ATTRIBUTE_PRINTF(3, 4);
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 13401
diff changeset
386 void class_format_error(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
387
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6605
diff changeset
388 Klass* load_class(Symbol* name, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
389
a61af66fc99e Initial load
duke
parents:
diff changeset
390 int change_sig_to_verificationType(
a61af66fc99e Initial load
duke
parents:
diff changeset
391 SignatureStream* sig_type, VerificationType* inference_type, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
392
a61af66fc99e Initial load
duke
parents:
diff changeset
393 VerificationType cp_index_to_type(int index, constantPoolHandle cp, TRAPS) {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
394 return VerificationType::reference_type(cp->klass_name_at(index));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
397 // Keep a list of temporary symbols created during verification because
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
398 // their reference counts need to be decrememented when the verifier object
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
399 // goes out of scope. Since these symbols escape the scope in which they're
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
400 // created, we can't use a TempNewSymbol.
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
401 Symbol* create_temporary_symbol(
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
402 const Symbol* s, int begin, int end, TRAPS);
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
403 Symbol* create_temporary_symbol(const char *s, int length, TRAPS);
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
404
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 2426
diff changeset
405 TypeOrigin ref_ctx(const char* str, TRAPS);
17573
aff11567504c 8035119: Fix exceptions to bytecode verification
hseigel
parents: 13401
diff changeset
406
0
a61af66fc99e Initial load
duke
parents:
diff changeset
407 };
a61af66fc99e Initial load
duke
parents:
diff changeset
408
a61af66fc99e Initial load
duke
parents:
diff changeset
409 inline int ClassVerifier::change_sig_to_verificationType(
a61af66fc99e Initial load
duke
parents:
diff changeset
410 SignatureStream* sig_type, VerificationType* inference_type, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
411 BasicType bt = sig_type->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
412 switch (bt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 case T_OBJECT:
a61af66fc99e Initial load
duke
parents:
diff changeset
414 case T_ARRAY:
a61af66fc99e Initial load
duke
parents:
diff changeset
415 {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
416 Symbol* name = sig_type->as_symbol(CHECK_0);
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
417 // Create another symbol to save as signature stream unreferences
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
418 // this symbol.
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
419 Symbol* name_copy =
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
420 create_temporary_symbol(name, 0, name->utf8_length(), CHECK_0);
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
421 assert(name_copy == name, "symbols don't match");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
422 *inference_type =
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
423 VerificationType::reference_type(name_copy);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
424 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
425 }
a61af66fc99e Initial load
duke
parents:
diff changeset
426 case T_LONG:
a61af66fc99e Initial load
duke
parents:
diff changeset
427 *inference_type = VerificationType::long_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
428 *++inference_type = VerificationType::long2_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
429 return 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
430 case T_DOUBLE:
a61af66fc99e Initial load
duke
parents:
diff changeset
431 *inference_type = VerificationType::double_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
432 *++inference_type = VerificationType::double2_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
433 return 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
434 case T_INT:
a61af66fc99e Initial load
duke
parents:
diff changeset
435 case T_BOOLEAN:
a61af66fc99e Initial load
duke
parents:
diff changeset
436 case T_BYTE:
a61af66fc99e Initial load
duke
parents:
diff changeset
437 case T_CHAR:
a61af66fc99e Initial load
duke
parents:
diff changeset
438 case T_SHORT:
a61af66fc99e Initial load
duke
parents:
diff changeset
439 *inference_type = VerificationType::integer_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
440 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
441 case T_FLOAT:
a61af66fc99e Initial load
duke
parents:
diff changeset
442 *inference_type = VerificationType::float_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
443 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
444 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
445 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
446 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
447 }
a61af66fc99e Initial load
duke
parents:
diff changeset
448 }
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
449
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
450 #endif // SHARE_VM_CLASSFILE_VERIFIER_HPP