1 /*
2 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
68 class StackMapFrame;
69 class StackMapTable;
70
71 // Summary of verifier's memory usage:
72 // StackMapTable is stack allocated.
73 // StackMapFrame are resource allocated. There is only one ResourceMark
74 // for each class verification, which is created at the top level.
75 // There is one mutable StackMapFrame (current_frame) which is updated
76 // by abstract bytecode interpretation. frame_in_exception_handler() returns
77 // a frame that has a mutable one-item stack (ready for pushing the
78 // catch type exception object). All the other StackMapFrame's
79 // are immutable (including their locals and stack arrays) after
80 // their constructions.
81 // locals/stack arrays in StackMapFrame are resource allocated.
82 // locals/stack arrays can be shared between StackMapFrame's, except
83 // the mutable StackMapFrame (current_frame).
84
85 // These macros are used similarly to CHECK macros but also check
86 // the status of the verifier and return if that has an error.
87 #define CHECK_VERIFY(verifier) \
88 CHECK); if ((verifier)->has_error()) return; (0
89 #define CHECK_VERIFY_(verifier, result) \
90 CHECK_(result)); if ((verifier)->has_error()) return (result); (0
91
92 // A new instance of this class is created for each class being verified
93 class ClassVerifier : public StackObj {
94 private:
95 Thread* _thread;
96 Symbol* _exception_type;
97 char* _message;
98 size_t _message_buffer_len;
99 GrowableArray<Symbol*>* _symbols; // keep a list of symbols created
100
101 void verify_method(methodHandle method, TRAPS);
102 char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
103 void verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS);
104 void verify_local_variable_table(u4 code_length, char* code_data, TRAPS);
105
106 VerificationType cp_ref_index_to_type(
107 int index, constantPoolHandle cp, TRAPS) {
108 return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD);
109 }
110
111 bool is_protected_access(
112 instanceKlassHandle this_class, klassOop target_class,
113 Symbol* field_name, Symbol* field_sig, bool is_method);
114
115 void verify_cp_index(constantPoolHandle cp, int index, TRAPS);
116 void verify_cp_type(
117 int index, constantPoolHandle cp, unsigned int types, TRAPS);
118 void verify_cp_class_type(int index, constantPoolHandle cp, TRAPS);
119
120 u2 verify_stackmap_table(
121 u2 stackmap_index, u2 bci, StackMapFrame* current_frame,
122 StackMapTable* stackmap_table, bool no_control_flow, TRAPS);
123
124 void verify_exception_handler_targets(
125 u2 bci, bool this_uninit, StackMapFrame* current_frame,
126 StackMapTable* stackmap_table, TRAPS);
127
128 void verify_ldc(
129 int opcode, u2 index, StackMapFrame *current_frame,
130 constantPoolHandle cp, u2 bci, TRAPS);
131
132 void verify_switch(
133 RawBytecodeStream* bcs, u4 code_length, char* code_data,
134 StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS);
135
136 void verify_field_instructions(
137 RawBytecodeStream* bcs, StackMapFrame* current_frame,
138 constantPoolHandle cp, TRAPS);
139
140 void verify_invoke_init(
141 RawBytecodeStream* bcs, VerificationType ref_class_type,
142 StackMapFrame* current_frame, u4 code_length, bool in_try_block,
143 bool* this_uninit, constantPoolHandle cp, StackMapTable* stackmap_table,
144 TRAPS);
145
146 // Used by ends_in_athrow() to push all handlers that contain bci onto
147 // the handler_stack, if the handler is not already on the stack.
148 void push_handlers(typeArrayHandle exhandlers,
149 GrowableArray<u4>* handler_stack,
150 u4 bci);
151
152 // Returns true if all paths starting with start_bc_offset end in athrow
153 // bytecode or loop.
154 bool ends_in_athrow(u4 start_bc_offset, TRAPS);
155
156 void verify_invoke_instructions(
157 RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
158 bool in_try_block, bool* this_uninit, VerificationType return_type,
159 constantPoolHandle cp, StackMapTable* stackmap_table, TRAPS);
160
161 VerificationType get_newarray_type(u2 index, u2 bci, TRAPS);
162 void verify_anewarray(
163 u2 index, constantPoolHandle cp, StackMapFrame* current_frame, TRAPS);
164 void verify_return_value(
165 VerificationType return_type, VerificationType type, u2 offset, TRAPS);
166
167 void verify_iload (u2 index, StackMapFrame* current_frame, TRAPS);
168 void verify_lload (u2 index, StackMapFrame* current_frame, TRAPS);
169 void verify_fload (u2 index, StackMapFrame* current_frame, TRAPS);
170 void verify_dload (u2 index, StackMapFrame* current_frame, TRAPS);
171 void verify_aload (u2 index, StackMapFrame* current_frame, TRAPS);
172 void verify_istore(u2 index, StackMapFrame* current_frame, TRAPS);
173 void verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS);
174 void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS);
175 void verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS);
176 void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS);
177 void verify_iinc (u2 index, StackMapFrame* current_frame, TRAPS);
178
179 bool name_in_supers(Symbol* ref_name, instanceKlassHandle current);
180
181 VerificationType object_type() const;
182
183 instanceKlassHandle _klass; // the class being verified
184 methodHandle _method; // current method being verified
185 VerificationType _this_type; // the verification type of the current class
186
187 // Some recursive calls from the verifier to the name resolver
188 // can cause the current class to be re-verified and rewritten.
189 // If this happens, the original verification should not continue,
190 // because constant pool indexes will have changed.
191 // The rewriter is preceded by the verifier. If the verifier throws
192 // an error, rewriting is prevented. Also, rewriting always precedes
193 // bytecode execution or compilation. Thus, is_rewritten implies
194 // that a class has been verified and prepared for execution.
195 bool was_recursively_verified() { return _klass->is_rewritten(); }
196
197 public:
198 enum {
199 BYTECODE_OFFSET = 1,
200 NEW_OFFSET = 2
201 };
202
203 // constructor
204 ClassVerifier(instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS);
205
206 // destructor
207 ~ClassVerifier();
208
209 Thread* thread() { return _thread; }
210 methodHandle method() { return _method; }
211 instanceKlassHandle current_class() const { return _klass; }
212 VerificationType current_type() const { return _this_type; }
213
214 // Verifies the class. If a verify or class file format error occurs,
215 // the '_exception_name' symbols will set to the exception name and
216 // the message_buffer will be filled in with the exception message.
217 void verify_class(TRAPS);
218
219 // Return status modes
220 Symbol* result() const { return _exception_type; }
221 bool has_error() const { return result() != NULL; }
222
223 // Called when verify or class format errors are encountered.
224 // May throw an exception based upon the mode.
225 void verify_error(u2 offset, const char* fmt, ...);
226 void verify_error(const char* fmt, ...);
227 void class_format_error(const char* fmt, ...);
228 void format_error_message(const char* fmt, int offset, va_list args);
229
230 klassOop load_class(Symbol* name, TRAPS);
231
232 int change_sig_to_verificationType(
233 SignatureStream* sig_type, VerificationType* inference_type, TRAPS);
234
235 VerificationType cp_index_to_type(int index, constantPoolHandle cp, TRAPS) {
236 return VerificationType::reference_type(cp->klass_name_at(index));
237 }
238
239 // Keep a list of temporary symbols created during verification because
240 // their reference counts need to be decrememented when the verifier object
241 // goes out of scope. Since these symbols escape the scope in which they're
242 // created, we can't use a TempNewSymbol.
243 Symbol* create_temporary_symbol(const Symbol* s, int begin, int end, TRAPS);
244 Symbol* create_temporary_symbol(const char *s, int length, TRAPS);
245
246 static bool _verify_verbose; // for debugging
247
248 };
249
250 inline int ClassVerifier::change_sig_to_verificationType(
251 SignatureStream* sig_type, VerificationType* inference_type, TRAPS) {
252 BasicType bt = sig_type->type();
253 switch (bt) {
254 case T_OBJECT:
255 case T_ARRAY:
256 {
257 Symbol* name = sig_type->as_symbol(CHECK_0);
258 // Create another symbol to save as signature stream unreferences
259 // this symbol.
260 Symbol* name_copy =
261 create_temporary_symbol(name, 0, name->utf8_length(), CHECK_0);
262 assert(name_copy == name, "symbols don't match");
263 *inference_type =
264 VerificationType::reference_type(name_copy);
265 return 1;
266 }
|
1 /*
2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
68 class StackMapFrame;
69 class StackMapTable;
70
71 // Summary of verifier's memory usage:
72 // StackMapTable is stack allocated.
73 // StackMapFrame are resource allocated. There is only one ResourceMark
74 // for each class verification, which is created at the top level.
75 // There is one mutable StackMapFrame (current_frame) which is updated
76 // by abstract bytecode interpretation. frame_in_exception_handler() returns
77 // a frame that has a mutable one-item stack (ready for pushing the
78 // catch type exception object). All the other StackMapFrame's
79 // are immutable (including their locals and stack arrays) after
80 // their constructions.
81 // locals/stack arrays in StackMapFrame are resource allocated.
82 // locals/stack arrays can be shared between StackMapFrame's, except
83 // the mutable StackMapFrame (current_frame).
84
85 // These macros are used similarly to CHECK macros but also check
86 // the status of the verifier and return if that has an error.
87 #define CHECK_VERIFY(verifier) \
88 CHECK); if ((verifier)->has_error()) return; ((void)0
89 #define CHECK_VERIFY_(verifier, result) \
90 CHECK_(result)); if ((verifier)->has_error()) return (result); ((void)0
91
92 class TypeOrigin VALUE_OBJ_CLASS_SPEC {
93 private:
94 typedef enum {
95 CF_LOCALS, // Comes from the current frame locals
96 CF_STACK, // Comes from the current frame expression stack
97 SM_LOCALS, // Comes from stackmap locals
98 SM_STACK, // Comes from stackmap expression stack
99 CONST_POOL, // Comes from the constant pool
100 SIG, // Comes from method signature
101 IMPLICIT, // Comes implicitly from code or context
102 BAD_INDEX, // No type, but the index is bad
103 FRAME_ONLY, // No type, context just contains the frame
104 NONE
105 } Origin;
106
107 Origin _origin;
108 u2 _index; // local, stack, or constant pool index
109 StackMapFrame* _frame; // source frame if CF or SM
110 VerificationType _type; // The actual type
111
112 TypeOrigin(
113 Origin origin, u2 index, StackMapFrame* frame, VerificationType type)
114 : _origin(origin), _index(index), _frame(frame), _type(type) {}
115
116 public:
117 TypeOrigin() : _origin(NONE), _index(0), _frame(NULL) {}
118
119 static TypeOrigin null();
120 static TypeOrigin local(u2 index, StackMapFrame* frame);
121 static TypeOrigin stack(u2 index, StackMapFrame* frame);
122 static TypeOrigin sm_local(u2 index, StackMapFrame* frame);
123 static TypeOrigin sm_stack(u2 index, StackMapFrame* frame);
124 static TypeOrigin cp(u2 index, VerificationType vt);
125 static TypeOrigin signature(VerificationType vt);
126 static TypeOrigin bad_index(u2 index);
127 static TypeOrigin implicit(VerificationType t);
128 static TypeOrigin frame(StackMapFrame* frame);
129
130 void reset_frame();
131 void details(outputStream* ss) const;
132 void print_frame(outputStream* ss) const;
133 const StackMapFrame* frame() const { return _frame; }
134 bool is_valid() const { return _origin != NONE; }
135 u2 index() const { return _index; }
136
137 #ifdef ASSERT
138 void print_on(outputStream* str) const;
139 #endif
140 };
141
142 class ErrorContext VALUE_OBJ_CLASS_SPEC {
143 private:
144 typedef enum {
145 INVALID_BYTECODE, // There was a problem with the bytecode
146 WRONG_TYPE, // Type value was not as expected
147 FLAGS_MISMATCH, // Frame flags are not assignable
148 BAD_CP_INDEX, // Invalid constant pool index
149 BAD_LOCAL_INDEX, // Invalid local index
150 LOCALS_SIZE_MISMATCH, // Frames have differing local counts
151 STACK_SIZE_MISMATCH, // Frames have different stack sizes
152 STACK_OVERFLOW, // Attempt to push onto a full expression stack
153 STACK_UNDERFLOW, // Attempt to pop and empty expression stack
154 MISSING_STACKMAP, // No stackmap for this location and there should be
155 BAD_STACKMAP, // Format error in stackmap
156 NO_FAULT, // No error
157 UNKNOWN
158 } FaultType;
159
160 int _bci;
161 FaultType _fault;
162 TypeOrigin _type;
163 TypeOrigin _expected;
164
165 ErrorContext(int bci, FaultType fault) :
166 _bci(bci), _fault(fault) {}
167 ErrorContext(int bci, FaultType fault, TypeOrigin type) :
168 _bci(bci), _fault(fault), _type(type) {}
169 ErrorContext(int bci, FaultType fault, TypeOrigin type, TypeOrigin exp) :
170 _bci(bci), _fault(fault), _type(type), _expected(exp) {}
171
172 public:
173 ErrorContext() : _bci(-1), _fault(NO_FAULT) {}
174
175 static ErrorContext bad_code(u2 bci) {
176 return ErrorContext(bci, INVALID_BYTECODE);
177 }
178 static ErrorContext bad_type(u2 bci, TypeOrigin type) {
179 return ErrorContext(bci, WRONG_TYPE, type);
180 }
181 static ErrorContext bad_type(u2 bci, TypeOrigin type, TypeOrigin exp) {
182 return ErrorContext(bci, WRONG_TYPE, type, exp);
183 }
184 static ErrorContext bad_flags(u2 bci, StackMapFrame* frame) {
185 return ErrorContext(bci, FLAGS_MISMATCH, TypeOrigin::frame(frame));
186 }
187 static ErrorContext bad_flags(u2 bci, StackMapFrame* cur, StackMapFrame* sm) {
188 return ErrorContext(bci, FLAGS_MISMATCH,
189 TypeOrigin::frame(cur), TypeOrigin::frame(sm));
190 }
191 static ErrorContext bad_cp_index(u2 bci, u2 index) {
192 return ErrorContext(bci, BAD_CP_INDEX, TypeOrigin::bad_index(index));
193 }
194 static ErrorContext bad_local_index(u2 bci, u2 index) {
195 return ErrorContext(bci, BAD_LOCAL_INDEX, TypeOrigin::bad_index(index));
196 }
197 static ErrorContext locals_size_mismatch(
198 u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) {
199 return ErrorContext(bci, LOCALS_SIZE_MISMATCH,
200 TypeOrigin::frame(frame0), TypeOrigin::frame(frame1));
201 }
202 static ErrorContext stack_size_mismatch(
203 u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) {
204 return ErrorContext(bci, STACK_SIZE_MISMATCH,
205 TypeOrigin::frame(frame0), TypeOrigin::frame(frame1));
206 }
207 static ErrorContext stack_overflow(u2 bci, StackMapFrame* frame) {
208 return ErrorContext(bci, STACK_OVERFLOW, TypeOrigin::frame(frame));
209 }
210 static ErrorContext stack_underflow(u2 bci, StackMapFrame* frame) {
211 return ErrorContext(bci, STACK_UNDERFLOW, TypeOrigin::frame(frame));
212 }
213 static ErrorContext missing_stackmap(u2 bci) {
214 return ErrorContext(bci, MISSING_STACKMAP);
215 }
216 static ErrorContext bad_stackmap(int index, StackMapFrame* frame) {
217 return ErrorContext(0, BAD_STACKMAP, TypeOrigin::frame(frame));
218 }
219
220 bool is_valid() const { return _fault != NO_FAULT; }
221 int bci() const { return _bci; }
222
223 void reset_frames() {
224 _type.reset_frame();
225 _expected.reset_frame();
226 }
227
228 void details(outputStream* ss, methodOop method) const;
229
230 #ifdef ASSERT
231 void print_on(outputStream* str) const {
232 str->print("error_context(%d, %d,", _bci, _fault);
233 _type.print_on(str);
234 str->print(",");
235 _expected.print_on(str);
236 str->print(")");
237 }
238 #endif
239
240 private:
241 void location_details(outputStream* ss, methodOop method) const;
242 void reason_details(outputStream* ss) const;
243 void frame_details(outputStream* ss) const;
244 void bytecode_details(outputStream* ss, methodOop method) const;
245 void handler_details(outputStream* ss, methodOop method) const;
246 void stackmap_details(outputStream* ss, methodOop method) const;
247 };
248
249 // A new instance of this class is created for each class being verified
250 class ClassVerifier : public StackObj {
251 private:
252 Thread* _thread;
253 GrowableArray<Symbol*>* _symbols; // keep a list of symbols created
254
255 Symbol* _exception_type;
256 char* _message;
257
258 ErrorContext _error_context; // contains information about an error
259
260 void verify_method(methodHandle method, TRAPS);
261 char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
262 void verify_exception_handler_table(u4 code_length, char* code_data,
263 int& min, int& max, TRAPS);
264 void verify_local_variable_table(u4 code_length, char* code_data, TRAPS);
265
266 VerificationType cp_ref_index_to_type(
267 int index, constantPoolHandle cp, TRAPS) {
268 return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD);
269 }
270
271 bool is_protected_access(
272 instanceKlassHandle this_class, klassOop target_class,
273 Symbol* field_name, Symbol* field_sig, bool is_method);
274
275 void verify_cp_index(u2 bci, constantPoolHandle cp, int index, TRAPS);
276 void verify_cp_type(u2 bci, int index, constantPoolHandle cp,
277 unsigned int types, TRAPS);
278 void verify_cp_class_type(u2 bci, int index, constantPoolHandle cp, TRAPS);
279
280 u2 verify_stackmap_table(
281 u2 stackmap_index, u2 bci, StackMapFrame* current_frame,
282 StackMapTable* stackmap_table, bool no_control_flow, TRAPS);
283
284 void verify_exception_handler_targets(
285 u2 bci, bool this_uninit, StackMapFrame* current_frame,
286 StackMapTable* stackmap_table, TRAPS);
287
288 void verify_ldc(
289 int opcode, u2 index, StackMapFrame *current_frame,
290 constantPoolHandle cp, u2 bci, TRAPS);
291
292 void verify_switch(
293 RawBytecodeStream* bcs, u4 code_length, char* code_data,
294 StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS);
295
296 void verify_field_instructions(
297 RawBytecodeStream* bcs, StackMapFrame* current_frame,
298 constantPoolHandle cp, TRAPS);
299
300 void verify_invoke_init(
301 RawBytecodeStream* bcs, u2 ref_index, VerificationType ref_class_type,
302 StackMapFrame* current_frame, u4 code_length, bool in_try_block,
303 bool* this_uninit, constantPoolHandle cp, StackMapTable* stackmap_table,
304 TRAPS);
305
306 // Used by ends_in_athrow() to push all handlers that contain bci onto
307 // the handler_stack, if the handler is not already on the stack.
308 void push_handlers(ExceptionTable* exhandlers,
309 GrowableArray<u4>* handler_stack,
310 u4 bci);
311
312 // Returns true if all paths starting with start_bc_offset end in athrow
313 // bytecode or loop.
314 bool ends_in_athrow(u4 start_bc_offset);
315
316 void verify_invoke_instructions(
317 RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
318 bool in_try_block, bool* this_uninit, VerificationType return_type,
319 constantPoolHandle cp, StackMapTable* stackmap_table, TRAPS);
320
321 VerificationType get_newarray_type(u2 index, u2 bci, TRAPS);
322 void verify_anewarray(u2 bci, u2 index, constantPoolHandle cp,
323 StackMapFrame* current_frame, TRAPS);
324 void verify_return_value(
325 VerificationType return_type, VerificationType type, u2 offset,
326 StackMapFrame* current_frame, TRAPS);
327
328 void verify_iload (u2 index, StackMapFrame* current_frame, TRAPS);
329 void verify_lload (u2 index, StackMapFrame* current_frame, TRAPS);
330 void verify_fload (u2 index, StackMapFrame* current_frame, TRAPS);
331 void verify_dload (u2 index, StackMapFrame* current_frame, TRAPS);
332 void verify_aload (u2 index, StackMapFrame* current_frame, TRAPS);
333 void verify_istore(u2 index, StackMapFrame* current_frame, TRAPS);
334 void verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS);
335 void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS);
336 void verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS);
337 void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS);
338 void verify_iinc (u2 index, StackMapFrame* current_frame, TRAPS);
339
340 bool name_in_supers(Symbol* ref_name, instanceKlassHandle current);
341
342 VerificationType object_type() const;
343
344 instanceKlassHandle _klass; // the class being verified
345 methodHandle _method; // current method being verified
346 VerificationType _this_type; // the verification type of the current class
347
348 // Some recursive calls from the verifier to the name resolver
349 // can cause the current class to be re-verified and rewritten.
350 // If this happens, the original verification should not continue,
351 // because constant pool indexes will have changed.
352 // The rewriter is preceded by the verifier. If the verifier throws
353 // an error, rewriting is prevented. Also, rewriting always precedes
354 // bytecode execution or compilation. Thus, is_rewritten implies
355 // that a class has been verified and prepared for execution.
356 bool was_recursively_verified() { return _klass->is_rewritten(); }
357
358 public:
359 enum {
360 BYTECODE_OFFSET = 1,
361 NEW_OFFSET = 2
362 };
363
364 // constructor
365 ClassVerifier(instanceKlassHandle klass, TRAPS);
366
367 // destructor
368 ~ClassVerifier();
369
370 Thread* thread() { return _thread; }
371 methodHandle method() { return _method; }
372 instanceKlassHandle current_class() const { return _klass; }
373 VerificationType current_type() const { return _this_type; }
374
375 // Verifies the class. If a verify or class file format error occurs,
376 // the '_exception_name' symbols will set to the exception name and
377 // the message_buffer will be filled in with the exception message.
378 void verify_class(TRAPS);
379
380 // Return status modes
381 Symbol* result() const { return _exception_type; }
382 bool has_error() const { return result() != NULL; }
383 char* exception_message() {
384 stringStream ss;
385 ss.print(_message);
386 _error_context.details(&ss, _method());
387 return ss.as_string();
388 }
389
390 // Called when verify or class format errors are encountered.
391 // May throw an exception based upon the mode.
392 void verify_error(ErrorContext ctx, const char* fmt, ...);
393 void class_format_error(const char* fmt, ...);
394
395 klassOop load_class(Symbol* name, TRAPS);
396
397 int change_sig_to_verificationType(
398 SignatureStream* sig_type, VerificationType* inference_type, TRAPS);
399
400 VerificationType cp_index_to_type(int index, constantPoolHandle cp, TRAPS) {
401 return VerificationType::reference_type(cp->klass_name_at(index));
402 }
403
404 // Keep a list of temporary symbols created during verification because
405 // their reference counts need to be decrememented when the verifier object
406 // goes out of scope. Since these symbols escape the scope in which they're
407 // created, we can't use a TempNewSymbol.
408 Symbol* create_temporary_symbol(
409 const Symbol* s, int begin, int end, TRAPS);
410 Symbol* create_temporary_symbol(const char *s, int length, TRAPS);
411
412 TypeOrigin ref_ctx(const char* str, TRAPS);
413
414 };
415
416 inline int ClassVerifier::change_sig_to_verificationType(
417 SignatureStream* sig_type, VerificationType* inference_type, TRAPS) {
418 BasicType bt = sig_type->type();
419 switch (bt) {
420 case T_OBJECT:
421 case T_ARRAY:
422 {
423 Symbol* name = sig_type->as_symbol(CHECK_0);
424 // Create another symbol to save as signature stream unreferences
425 // this symbol.
426 Symbol* name_copy =
427 create_temporary_symbol(name, 0, name->utf8_length(), CHECK_0);
428 assert(name_copy == name, "symbols don't match");
429 *inference_type =
430 VerificationType::reference_type(name_copy);
431 return 1;
432 }
|