1 /* |
1 /* |
2 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
49 * then the appropriate VerifyError or ClassFormatError will be thrown. |
49 * then the appropriate VerifyError or ClassFormatError will be thrown. |
50 * Otherwise, no exception is thrown and the return indicates the |
50 * Otherwise, no exception is thrown and the return indicates the |
51 * error. |
51 * error. |
52 */ |
52 */ |
53 static void log_end_verification(outputStream* st, const char* klassName, Symbol* exception_name, TRAPS); |
53 static void log_end_verification(outputStream* st, const char* klassName, Symbol* exception_name, TRAPS); |
54 static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS); |
54 static bool verify(InstanceKlass* klass, Mode mode, bool should_verify_class, TRAPS); |
55 |
55 |
56 // Return false if the class is loaded by the bootstrap loader, |
56 // Return false if the class is loaded by the bootstrap loader, |
57 // or if defineClass was called requesting skipping verification |
57 // or if defineClass was called requesting skipping verification |
58 // -Xverify:all/none override this value |
58 // -Xverify:all/none override this value |
59 static bool should_verify_for(oop class_loader, bool should_verify_class); |
59 static bool should_verify_for(oop class_loader, bool should_verify_class); |
63 |
63 |
64 // Print output for class+resolve |
64 // Print output for class+resolve |
65 static void trace_class_resolution(Klass* resolve_class, InstanceKlass* verify_class); |
65 static void trace_class_resolution(Klass* resolve_class, InstanceKlass* verify_class); |
66 |
66 |
67 private: |
67 private: |
68 static bool is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class); |
68 static bool is_eligible_for_verification(InstanceKlass* klass, bool should_verify_class); |
69 static Symbol* inference_verify( |
69 static Symbol* inference_verify( |
70 instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS); |
70 InstanceKlass* klass, char* msg, size_t msg_len, TRAPS); |
71 }; |
71 }; |
72 |
72 |
73 class RawBytecodeStream; |
73 class RawBytecodeStream; |
74 class StackMapFrame; |
74 class StackMapFrame; |
75 class StackMapTable; |
75 class StackMapTable; |
273 int index, const constantPoolHandle& cp, TRAPS) { |
273 int index, const constantPoolHandle& cp, TRAPS) { |
274 return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD); |
274 return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD); |
275 } |
275 } |
276 |
276 |
277 bool is_protected_access( |
277 bool is_protected_access( |
278 instanceKlassHandle this_class, Klass* target_class, |
278 InstanceKlass* this_class, Klass* target_class, |
279 Symbol* field_name, Symbol* field_sig, bool is_method); |
279 Symbol* field_name, Symbol* field_sig, bool is_method); |
280 |
280 |
281 void verify_cp_index(u2 bci, const constantPoolHandle& cp, int index, TRAPS); |
281 void verify_cp_index(u2 bci, const constantPoolHandle& cp, int index, TRAPS); |
282 void verify_cp_type(u2 bci, int index, const constantPoolHandle& cp, |
282 void verify_cp_type(u2 bci, int index, const constantPoolHandle& cp, |
283 unsigned int types, TRAPS); |
283 unsigned int types, TRAPS); |
342 void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS); |
342 void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS); |
343 void verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS); |
343 void verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS); |
344 void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS); |
344 void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS); |
345 void verify_iinc (u2 index, StackMapFrame* current_frame, TRAPS); |
345 void verify_iinc (u2 index, StackMapFrame* current_frame, TRAPS); |
346 |
346 |
347 bool name_in_supers(Symbol* ref_name, instanceKlassHandle current); |
347 bool name_in_supers(Symbol* ref_name, InstanceKlass* current); |
348 |
348 |
349 VerificationType object_type() const; |
349 VerificationType object_type() const; |
350 |
350 |
351 instanceKlassHandle _klass; // the class being verified |
351 InstanceKlass* _klass; // the class being verified |
352 methodHandle _method; // current method being verified |
352 methodHandle _method; // current method being verified |
353 VerificationType _this_type; // the verification type of the current class |
353 VerificationType _this_type; // the verification type of the current class |
354 |
354 |
355 // Some recursive calls from the verifier to the name resolver |
355 // Some recursive calls from the verifier to the name resolver |
356 // can cause the current class to be re-verified and rewritten. |
356 // can cause the current class to be re-verified and rewritten. |
360 // an error, rewriting is prevented. Also, rewriting always precedes |
360 // an error, rewriting is prevented. Also, rewriting always precedes |
361 // bytecode execution or compilation. Thus, is_rewritten implies |
361 // bytecode execution or compilation. Thus, is_rewritten implies |
362 // that a class has been verified and prepared for execution. |
362 // that a class has been verified and prepared for execution. |
363 bool was_recursively_verified() { return _klass->is_rewritten(); } |
363 bool was_recursively_verified() { return _klass->is_rewritten(); } |
364 |
364 |
365 bool is_same_or_direct_interface(instanceKlassHandle klass, |
365 bool is_same_or_direct_interface(InstanceKlass* klass, |
366 VerificationType klass_type, VerificationType ref_class_type); |
366 VerificationType klass_type, VerificationType ref_class_type); |
367 |
367 |
368 public: |
368 public: |
369 enum { |
369 enum { |
370 BYTECODE_OFFSET = 1, |
370 BYTECODE_OFFSET = 1, |
371 NEW_OFFSET = 2 |
371 NEW_OFFSET = 2 |
372 }; |
372 }; |
373 |
373 |
374 // constructor |
374 // constructor |
375 ClassVerifier(instanceKlassHandle klass, TRAPS); |
375 ClassVerifier(InstanceKlass* klass, TRAPS); |
376 |
376 |
377 // destructor |
377 // destructor |
378 ~ClassVerifier(); |
378 ~ClassVerifier(); |
379 |
379 |
380 Thread* thread() { return _thread; } |
380 Thread* thread() { return _thread; } |
381 const methodHandle& method() { return _method; } |
381 const methodHandle& method() { return _method; } |
382 instanceKlassHandle current_class() const { return _klass; } |
382 InstanceKlass* current_class() const { return _klass; } |
383 VerificationType current_type() const { return _this_type; } |
383 VerificationType current_type() const { return _this_type; } |
384 |
384 |
385 // Verifies the class. If a verify or class file format error occurs, |
385 // Verifies the class. If a verify or class file format error occurs, |
386 // the '_exception_name' symbols will set to the exception name and |
386 // the '_exception_name' symbols will set to the exception name and |
387 // the message_buffer will be filled in with the exception message. |
387 // the message_buffer will be filled in with the exception message. |