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, const Method* method) const;
242 void reason_details(outputStream* ss) const;
243 void frame_details(outputStream* ss) const;
244 void bytecode_details(outputStream* ss, const Method* method) const;
245 void handler_details(outputStream* ss, const Method* method) const;
246 void stackmap_details(outputStream* ss, const Method* 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(const methodHandle& method, TRAPS);
261 char* generate_code_data(const 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, const 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 InstanceKlass* this_class, Klass* target_class,
394 // Called when verify or class format errors are encountered.
395 // May throw an exception based upon the mode.
396 void verify_error(ErrorContext ctx, const char* fmt, ...) ATTRIBUTE_PRINTF(3, 4);
397 void class_format_error(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3);
398
399 Klass* load_class(Symbol* name, TRAPS);
400
401 int change_sig_to_verificationType(
402 SignatureStream* sig_type, VerificationType* inference_type, TRAPS);
403
404 VerificationType cp_index_to_type(int index, const constantPoolHandle& cp, TRAPS) {
405 return VerificationType::reference_type(cp->klass_name_at(index));
406 }
407
408 // Keep a list of temporary symbols created during verification because
409 // their reference counts need to be decremented when the verifier object
410 // goes out of scope. Since these symbols escape the scope in which they're
411 // created, we can't use a TempNewSymbol.
412 Symbol* create_temporary_symbol(const Symbol* s, int begin, int end, TRAPS);
413 Symbol* create_temporary_symbol(const char *s, int length, TRAPS);
414
415 Symbol* create_temporary_symbol(Symbol* s) {
416 // This version just updates the reference count and saves the symbol to be
417 // dereferenced later.
418 s->increment_refcount();
419 _symbols->push(s);
420 return s;
421 }
422
423 TypeOrigin ref_ctx(const char* str, TRAPS);
424
425 };
426
427 inline int ClassVerifier::change_sig_to_verificationType(
428 SignatureStream* sig_type, VerificationType* inference_type, TRAPS) {
429 BasicType bt = sig_type->type();
430 switch (bt) {
431 case T_OBJECT:
432 case T_ARRAY:
433 {
434 Symbol* name = sig_type->as_symbol(CHECK_0);
435 // Create another symbol to save as signature stream unreferences this symbol.
436 Symbol* name_copy = create_temporary_symbol(name);
437 assert(name_copy == name, "symbols don't match");
438 *inference_type =
439 VerificationType::reference_type(name_copy);
|
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, const Method* method) const;
242 void reason_details(outputStream* ss) const;
243 void frame_details(outputStream* ss) const;
244 void bytecode_details(outputStream* ss, const Method* method) const;
245 void handler_details(outputStream* ss, const Method* method) const;
246 void stackmap_details(outputStream* ss, const Method* 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
254 Symbol* _previous_symbol; // cache of the previously looked up symbol
255 GrowableArray<Symbol*>* _symbols; // keep a list of symbols created
256
257 Symbol* _exception_type;
258 char* _message;
259
260 ErrorContext _error_context; // contains information about an error
261
262 void verify_method(const methodHandle& method, TRAPS);
263 char* generate_code_data(const methodHandle& m, u4 code_length, TRAPS);
264 void verify_exception_handler_table(u4 code_length, char* code_data,
265 int& min, int& max, TRAPS);
266 void verify_local_variable_table(u4 code_length, char* code_data, TRAPS);
267
268 VerificationType cp_ref_index_to_type(
269 int index, const constantPoolHandle& cp, TRAPS) {
270 return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD);
271 }
272
273 bool is_protected_access(
274 InstanceKlass* this_class, Klass* target_class,
396 // Called when verify or class format errors are encountered.
397 // May throw an exception based upon the mode.
398 void verify_error(ErrorContext ctx, const char* fmt, ...) ATTRIBUTE_PRINTF(3, 4);
399 void class_format_error(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3);
400
401 Klass* load_class(Symbol* name, TRAPS);
402
403 int change_sig_to_verificationType(
404 SignatureStream* sig_type, VerificationType* inference_type, TRAPS);
405
406 VerificationType cp_index_to_type(int index, const constantPoolHandle& cp, TRAPS) {
407 return VerificationType::reference_type(cp->klass_name_at(index));
408 }
409
410 // Keep a list of temporary symbols created during verification because
411 // their reference counts need to be decremented when the verifier object
412 // goes out of scope. Since these symbols escape the scope in which they're
413 // created, we can't use a TempNewSymbol.
414 Symbol* create_temporary_symbol(const Symbol* s, int begin, int end, TRAPS);
415 Symbol* create_temporary_symbol(const char *s, int length, TRAPS);
416 Symbol* create_temporary_symbol(Symbol* s) {
417 if (s == _previous_symbol) {
418 return s;
419 }
420 if (!s->is_permanent()) {
421 s->increment_refcount();
422 if (_symbols == NULL) {
423 _symbols = new GrowableArray<Symbol*>(50, 0, NULL);
424 }
425 _symbols->push(s);
426 }
427 _previous_symbol = s;
428 return s;
429 }
430
431 TypeOrigin ref_ctx(const char* str, TRAPS);
432
433 };
434
435 inline int ClassVerifier::change_sig_to_verificationType(
436 SignatureStream* sig_type, VerificationType* inference_type, TRAPS) {
437 BasicType bt = sig_type->type();
438 switch (bt) {
439 case T_OBJECT:
440 case T_ARRAY:
441 {
442 Symbol* name = sig_type->as_symbol(CHECK_0);
443 // Create another symbol to save as signature stream unreferences this symbol.
444 Symbol* name_copy = create_temporary_symbol(name);
445 assert(name_copy == name, "symbols don't match");
446 *inference_type =
447 VerificationType::reference_type(name_copy);
|