annotate src/share/vm/classfile/verifier.hpp @ 3762:5c0a3c1858b1

7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359 Summary: The LNC array is sized before the start of a scavenge, while the heap may expand during a scavenge. With CMS, the last block of an arbitrary suffice of the LNC array may expand due to coalition with the expansion delta. We now take care not to attempt access past the end of the LNC array. LNC array code will be cleaned up and suitably encapsulated as part of the forthcoming performance RFE 7043675. Reviewed-by: brutisso
author ysr
date Thu, 02 Jun 2011 10:23:36 -0700
parents 1d1603768966
children 4ee06e614636
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2426
1d1603768966 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 2177
diff changeset
2 * Copyright (c) 1998, 2011, 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"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
31 #include "oops/methodOop.hpp"
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 {
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
39 STACKMAP_ATTRIBUTE_MAJOR_VERSION = 50,
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
40 INVOKEDYNAMIC_MAJOR_VERSION = 51
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
41 };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
42 typedef enum { ThrowException, NoException } Mode;
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
45 * Verify the bytecodes for a class. If 'throw_exception' is true
a61af66fc99e Initial load
duke
parents:
diff changeset
46 * then the appropriate VerifyError or ClassFormatError will be thrown.
a61af66fc99e Initial load
duke
parents:
diff changeset
47 * Otherwise, no exception is thrown and the return indicates the
a61af66fc99e Initial load
duke
parents:
diff changeset
48 * error.
a61af66fc99e Initial load
duke
parents:
diff changeset
49 */
973
ad6585fd4087 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 0
diff changeset
50 static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
51
973
ad6585fd4087 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 0
diff changeset
52 // Return false if the class is loaded by the bootstrap loader,
ad6585fd4087 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 0
diff changeset
53 // or if defineClass was called requesting skipping verification
ad6585fd4087 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 0
diff changeset
54 // -Xverify:all/none override this value
ad6585fd4087 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 0
diff changeset
55 static bool should_verify_for(oop class_loader, bool should_verify_class);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // Relax certain verifier checks to enable some broken 1.1 apps to run on 1.2.
a61af66fc99e Initial load
duke
parents:
diff changeset
58 static bool relax_verify_for(oop class_loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 private:
973
ad6585fd4087 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 0
diff changeset
61 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
62 static Symbol* inference_verify(
0
a61af66fc99e Initial load
duke
parents:
diff changeset
63 instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 };
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 class RawBytecodeStream;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 class StackMapFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 class StackMapTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // Summary of verifier's memory usage:
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // StackMapTable is stack allocated.
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
72 // 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
73 // for each class verification, which is created at the top level.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // There is one mutable StackMapFrame (current_frame) which is updated
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // by abstract bytecode interpretation. frame_in_exception_handler() returns
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // a frame that has a mutable one-item stack (ready for pushing the
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // catch type exception object). All the other StackMapFrame's
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // are immutable (including their locals and stack arrays) after
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // their constructions.
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // locals/stack arrays in StackMapFrame are resource allocated.
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // locals/stack arrays can be shared between StackMapFrame's, except
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // the mutable StackMapFrame (current_frame).
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // These macros are used similarly to CHECK macros but also check
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // the status of the verifier and return if that has an error.
a61af66fc99e Initial load
duke
parents:
diff changeset
86 #define CHECK_VERIFY(verifier) \
a61af66fc99e Initial load
duke
parents:
diff changeset
87 CHECK); if ((verifier)->has_error()) return; (0
a61af66fc99e Initial load
duke
parents:
diff changeset
88 #define CHECK_VERIFY_(verifier, result) \
a61af66fc99e Initial load
duke
parents:
diff changeset
89 CHECK_(result)); if ((verifier)->has_error()) return (result); (0
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // A new instance of this class is created for each class being verified
a61af66fc99e Initial load
duke
parents:
diff changeset
92 class ClassVerifier : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
94 Thread* _thread;
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
95 Symbol* _exception_type;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
96 char* _message;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 size_t _message_buffer_len;
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
98 GrowableArray<Symbol*>* _symbols; // keep a list of symbols created
0
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 void verify_method(methodHandle method, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 void verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 void verify_local_variable_table(u4 code_length, char* code_data, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 VerificationType cp_ref_index_to_type(
a61af66fc99e Initial load
duke
parents:
diff changeset
106 int index, constantPoolHandle cp, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 bool is_protected_access(
a61af66fc99e Initial load
duke
parents:
diff changeset
111 instanceKlassHandle this_class, klassOop target_class,
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
112 Symbol* field_name, Symbol* field_sig, bool is_method);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 void verify_cp_index(constantPoolHandle cp, int index, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 void verify_cp_type(
a61af66fc99e Initial load
duke
parents:
diff changeset
116 int index, constantPoolHandle cp, unsigned int types, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 void verify_cp_class_type(int index, constantPoolHandle cp, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 u2 verify_stackmap_table(
a61af66fc99e Initial load
duke
parents:
diff changeset
120 u2 stackmap_index, u2 bci, StackMapFrame* current_frame,
a61af66fc99e Initial load
duke
parents:
diff changeset
121 StackMapTable* stackmap_table, bool no_control_flow, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 void verify_exception_handler_targets(
a61af66fc99e Initial load
duke
parents:
diff changeset
124 u2 bci, bool this_uninit, StackMapFrame* current_frame,
a61af66fc99e Initial load
duke
parents:
diff changeset
125 StackMapTable* stackmap_table, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 void verify_ldc(
a61af66fc99e Initial load
duke
parents:
diff changeset
128 int opcode, u2 index, StackMapFrame *current_frame,
a61af66fc99e Initial load
duke
parents:
diff changeset
129 constantPoolHandle cp, u2 bci, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 void verify_switch(
a61af66fc99e Initial load
duke
parents:
diff changeset
132 RawBytecodeStream* bcs, u4 code_length, char* code_data,
a61af66fc99e Initial load
duke
parents:
diff changeset
133 StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 void verify_field_instructions(
a61af66fc99e Initial load
duke
parents:
diff changeset
136 RawBytecodeStream* bcs, StackMapFrame* current_frame,
a61af66fc99e Initial load
duke
parents:
diff changeset
137 constantPoolHandle cp, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 void verify_invoke_init(
a61af66fc99e Initial load
duke
parents:
diff changeset
140 RawBytecodeStream* bcs, VerificationType ref_class_type,
a61af66fc99e Initial load
duke
parents:
diff changeset
141 StackMapFrame* current_frame, u4 code_length, bool* this_uninit,
a61af66fc99e Initial load
duke
parents:
diff changeset
142 constantPoolHandle cp, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 void verify_invoke_instructions(
a61af66fc99e Initial load
duke
parents:
diff changeset
145 RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
a61af66fc99e Initial load
duke
parents:
diff changeset
146 bool* this_uninit, VerificationType return_type,
a61af66fc99e Initial load
duke
parents:
diff changeset
147 constantPoolHandle cp, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 VerificationType get_newarray_type(u2 index, u2 bci, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 void verify_anewarray(
a61af66fc99e Initial load
duke
parents:
diff changeset
151 u2 index, constantPoolHandle cp, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 void verify_return_value(
a61af66fc99e Initial load
duke
parents:
diff changeset
153 VerificationType return_type, VerificationType type, u2 offset, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 void verify_iload (u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 void verify_lload (u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 void verify_fload (u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 void verify_dload (u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 void verify_aload (u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 void verify_istore(u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
161 void verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 void verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 void verify_iinc (u2 index, StackMapFrame* current_frame, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
166
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
167 bool name_in_supers(Symbol* ref_name, instanceKlassHandle current);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
168
1955
1070423b51f3 6865028: Illegal instructions passing verification prior to 'invokespecial Object.<init>'
kamg
parents: 1602
diff changeset
169 VerificationType object_type() const;
1070423b51f3 6865028: Illegal instructions passing verification prior to 'invokespecial Object.<init>'
kamg
parents: 1602
diff changeset
170
0
a61af66fc99e Initial load
duke
parents:
diff changeset
171 instanceKlassHandle _klass; // the class being verified
a61af66fc99e Initial load
duke
parents:
diff changeset
172 methodHandle _method; // current method being verified
a61af66fc99e Initial load
duke
parents:
diff changeset
173 VerificationType _this_type; // the verification type of the current class
a61af66fc99e Initial load
duke
parents:
diff changeset
174
1570
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
175 // Some recursive calls from the verifier to the name resolver
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
176 // can cause the current class to be re-verified and rewritten.
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
177 // If this happens, the original verification should not continue,
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
178 // because constant pool indexes will have changed.
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
179 // The rewriter is preceded by the verifier. If the verifier throws
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
180 // an error, rewriting is prevented. Also, rewriting always precedes
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
181 // bytecode execution or compilation. Thus, is_rewritten implies
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
182 // that a class has been verified and prepared for execution.
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
183 bool was_recursively_verified() { return _klass->is_rewritten(); }
de91a2f25c7e 6956164: nightly regressions from 6939207
jrose
parents: 973
diff changeset
184
0
a61af66fc99e Initial load
duke
parents:
diff changeset
185 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
186 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 BYTECODE_OFFSET = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
188 NEW_OFFSET = 2
a61af66fc99e Initial load
duke
parents:
diff changeset
189 };
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
192 ClassVerifier(instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // destructor
a61af66fc99e Initial load
duke
parents:
diff changeset
195 ~ClassVerifier();
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 Thread* thread() { return _thread; }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 methodHandle method() { return _method; }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 instanceKlassHandle current_class() const { return _klass; }
a61af66fc99e Initial load
duke
parents:
diff changeset
200 VerificationType current_type() const { return _this_type; }
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // Verifies the class. If a verify or class file format error occurs,
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // the '_exception_name' symbols will set to the exception name and
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // the message_buffer will be filled in with the exception message.
a61af66fc99e Initial load
duke
parents:
diff changeset
205 void verify_class(TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // Return status modes
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
208 Symbol* result() const { return _exception_type; }
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
209 bool has_error() const { return result() != NULL; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // Called when verify or class format errors are encountered.
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // May throw an exception based upon the mode.
a61af66fc99e Initial load
duke
parents:
diff changeset
213 void verify_error(u2 offset, const char* fmt, ...);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 void verify_error(const char* fmt, ...);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 void class_format_error(const char* fmt, ...);
a61af66fc99e Initial load
duke
parents:
diff changeset
216 void format_error_message(const char* fmt, int offset, va_list args);
a61af66fc99e Initial load
duke
parents:
diff changeset
217
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
218 klassOop load_class(Symbol* name, TRAPS);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 int change_sig_to_verificationType(
a61af66fc99e Initial load
duke
parents:
diff changeset
221 SignatureStream* sig_type, VerificationType* inference_type, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 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
224 return VerificationType::reference_type(cp->klass_name_at(index));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
227 // 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
228 // 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
229 // 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
230 // created, we can't use a TempNewSymbol.
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
231 Symbol* create_temporary_symbol(const Symbol* s, int begin, int end, TRAPS);
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
232 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
233
0
a61af66fc99e Initial load
duke
parents:
diff changeset
234 static bool _verify_verbose; // for debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
235 };
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237 inline int ClassVerifier::change_sig_to_verificationType(
a61af66fc99e Initial load
duke
parents:
diff changeset
238 SignatureStream* sig_type, VerificationType* inference_type, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 BasicType bt = sig_type->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
240 switch (bt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 case T_OBJECT:
a61af66fc99e Initial load
duke
parents:
diff changeset
242 case T_ARRAY:
a61af66fc99e Initial load
duke
parents:
diff changeset
243 {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
244 Symbol* name = sig_type->as_symbol(CHECK_0);
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
245 // 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
246 // this symbol.
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
247 Symbol* name_copy =
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
248 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
249 assert(name_copy == name, "symbols don't match");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
250 *inference_type =
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
251 VerificationType::reference_type(name_copy);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
252 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
254 case T_LONG:
a61af66fc99e Initial load
duke
parents:
diff changeset
255 *inference_type = VerificationType::long_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
256 *++inference_type = VerificationType::long2_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
257 return 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
258 case T_DOUBLE:
a61af66fc99e Initial load
duke
parents:
diff changeset
259 *inference_type = VerificationType::double_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
260 *++inference_type = VerificationType::double2_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
261 return 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 case T_INT:
a61af66fc99e Initial load
duke
parents:
diff changeset
263 case T_BOOLEAN:
a61af66fc99e Initial load
duke
parents:
diff changeset
264 case T_BYTE:
a61af66fc99e Initial load
duke
parents:
diff changeset
265 case T_CHAR:
a61af66fc99e Initial load
duke
parents:
diff changeset
266 case T_SHORT:
a61af66fc99e Initial load
duke
parents:
diff changeset
267 *inference_type = VerificationType::integer_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
268 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
269 case T_FLOAT:
a61af66fc99e Initial load
duke
parents:
diff changeset
270 *inference_type = VerificationType::float_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
271 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
272 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
273 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
274 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
277
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1955
diff changeset
278 #endif // SHARE_VM_CLASSFILE_VERIFIER_HPP