ulclassinit02 Sdiff src/share/vm/classfile (original) (raw)


31 #include "classfile/systemDictionary.hpp" 32 #include "classfile/verifier.hpp" 33 #include "classfile/vmSymbols.hpp" 34 #include "interpreter/bytecodes.hpp" 35 #include "interpreter/bytecodeStream.hpp" 36 #include "memory/oopFactory.hpp" 37 #include "memory/resourceArea.hpp" 38 #include "oops/instanceKlass.hpp" 39 #include "oops/oop.inline.hpp" 40 #include "oops/typeArrayOop.hpp" 41 #include "prims/jvm.h" 42 #include "runtime/fieldDescriptor.hpp" 43 #include "runtime/handles.inline.hpp" 44 #include "runtime/interfaceSupport.hpp" 45 #include "runtime/javaCalls.hpp" 46 #include "runtime/orderAccess.inline.hpp" 47 #include "runtime/os.hpp" 48 #include "runtime/thread.hpp" 49 #include "services/threadService.hpp" 50 #include "utilities/bytes.hpp"

51 52 #define NOFAILOVER_MAJOR_VERSION 51 53 #define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION 51 54 #define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION 52 55 56 // Access to external entry for VerifyClassCodes - old byte code verifier 57 58 extern "C" { 59 typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint); 60 typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv , jclass, char , jint, jint); 61 } 62 63 static void volatile _verify_byte_codes_fn = NULL; 64 65 static volatile jint _is_new_verify_byte_codes_fn = (jint) true; 66 67 static void verify_byte_codes_fn() { 68 if (_verify_byte_codes_fn == NULL) { 69 void *lib_handle = os::native_java_library(); 70 void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion");


94 // verifyRemote 95 (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted); 96 return !need_verify; 97 } 98 99 void Verifier::trace_class_resolution(Klass* resolve_class, InstanceKlass* verify_class) { 100 assert(verify_class != NULL, "Unexpected null verify_class"); 101 ResourceMark rm; 102 Symbol* s = verify_class->source_file_name(); 103 const char* source_file = (s != NULL ? s->as_C_string() : NULL); 104 const char* verify = verify_class->external_name(); 105 const char* resolve = resolve_class->external_name(); 106 // print in a single call to reduce interleaving between threads 107 if (source_file != NULL) { 108 tty->print("RESOLVE %s %s %s (verification)\n", verify, resolve, source_file); 109 } else { 110 tty->print("RESOLVE %s %s (verification)\n", verify, resolve); 111 } 112 } 113

114 bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) { 115 HandleMark hm; 116 ResourceMark rm(THREAD); 117 118 // Eagerly allocate the identity hash code for a klass. This is a fallout 119 // from 6320749 and 8059924: hash code generator is not supposed to be called 120 // during the safepoint, but it allows to sneak the hashcode in during 121 // verification. Without this eager hashcode generation, we may end up 122 // installing the hashcode during some other operation, which may be at 123 // safepoint -- blowing up the checks. It was previously done as the side 124 // effect (sic!) for external_name(), but instead of doing that, we opt to 125 // explicitly push the hashcode in here. This is signify the following block 126 // is IMPORTANT: 127 if (klass->java_mirror() != NULL) { 128 klass->java_mirror()->identity_hash(); 129 } 130 131 if (!is_eligible_for_verification(klass, should_verify_class)) { 132 return true; 133 }


138 PerfClassTraceTime timer(ClassLoader::perf_class_verify_time(), 139 ClassLoader::perf_class_verify_selftime(), 140 ClassLoader::perf_classes_verified(), 141 jt->get_thread_stat()->perf_recursion_counts_addr(), 142 jt->get_thread_stat()->perf_timers_addr(), 143 PerfClassTraceTime::CLASS_VERIFY); 144 145 // If the class should be verified, first see if we can use the split 146 // verifier. If not, or if verification fails and FailOverToOldVerifier 147 // is set, then call the inference verifier. 148 149 Symbol* exception_name = NULL; 150 const size_t message_buffer_len = klass->name()->utf8_length() + 1024; 151 char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len); 152 char* exception_message = message_buffer; 153 154 const char* klassName = klass->external_name(); 155 bool can_failover = FailOverToOldVerifier && 156 klass->major_version() < NOFAILOVER_MAJOR_VERSION; 157 158 if (TraceClassInitialization) { 159 tty->print_cr("Start class verification for: %s", klassName); 160 } 161 if (klass->major_version() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) { 162 ClassVerifier split_verifier(klass, THREAD); 163 split_verifier.verify_class(THREAD); 164 exception_name = split_verifier.result(); 165 if (can_failover && !HAS_PENDING_EXCEPTION && 166 (exception_name == vmSymbols::java_lang_VerifyError() || 167 exception_name == vmSymbols::java_lang_ClassFormatError())) { 168 if (TraceClassInitialization || VerboseVerification) { 169 tty->print_cr( 170 "Fail over class verification to old verifier for: %s", klassName); 171 }

172 exception_name = inference_verify( 173 klass, message_buffer, message_buffer_len, THREAD); 174 } 175 if (exception_name != NULL) { 176 exception_message = split_verifier.exception_message(); 177 } 178 } else { 179 exception_name = inference_verify( 180 klass, message_buffer, message_buffer_len, THREAD); 181 } 182 183 if (TraceClassInitialization || VerboseVerification) { 184 if (HAS_PENDING_EXCEPTION) { 185 tty->print("Verification for %s has", klassName); 186 tty->print_cr(" exception pending %s ", 187 PENDING_EXCEPTION->klass()->external_name()); 188 } else if (exception_name != NULL) { 189 tty->print_cr("Verification for %s failed", klassName); 190 } 191 tty->print_cr("End class verification for: %s", klassName);

192 } 193 194 if (HAS_PENDING_EXCEPTION) { 195 return false; // use the existing exception 196 } else if (exception_name == NULL) { 197 return true; // verifcation succeeded 198 } else { // VerifyError or ClassFormatError to be created and thrown 199 ResourceMark rm(THREAD); 200 instanceKlassHandle kls = 201 SystemDictionary::resolve_or_fail(exception_name, true, CHECK_false); 202 if (TraceClassResolution) { 203 Verifier::trace_class_resolution(kls(), klass()); 204 } 205 206 while (!kls.is_null()) { 207 if (kls == klass) { 208 // If the class being verified is the exception we're creating 209 // or one of it's superclasses, we're in trouble and are going 210 // to infinitely recurse when we try to initialize the exception. 211 // So bail out here by throwing the preallocated VM error.


581 _klass->external_name()); 582 } 583 584 Array<Method*>* methods = _klass->methods(); 585 int num_methods = methods->length(); 586 587 for (int index = 0; index < num_methods; index++) { 588 // Check for recursive re-verification before each method. 589 if (was_recursively_verified()) return; 590 591 Method* m = methods->at(index); 592 if (m->is_native() || m->is_abstract() || m->is_overpass()) { 593 // If m is native or abstract, skip it. It is checked in class file 594 // parser that methods do not override a final method. Overpass methods 595 // are trusted since the VM generates them. 596 continue; 597 } 598 verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this)); 599 } 600 601 if (VerboseVerification || TraceClassInitialization) { 602 if (was_recursively_verified()) 603 tty->print_cr("Recursive verification detected for: %s",

604 _klass->external_name()); 605 } 606 } 607 608 void ClassVerifier::verify_method(const methodHandle& m, TRAPS) { 609 HandleMark hm(THREAD); 610 _method = m; // initialize _method 611 if (VerboseVerification) { 612 tty->print_cr("Verifying method %s", m->name_and_sig_as_C_string()); 613 } 614 615 // For clang, the only good constant format string is a literal constant format string. 616 #define bad_type_msg "Bad type on operand stack in %s" 617 618 int32_t max_stack = m->verifier_max_stack(); 619 int32_t max_locals = m->max_locals(); 620 constantPoolHandle cp(THREAD, m->constants()); 621 622 if (!SignatureVerifier::is_valid_method_signature(m->signature())) { 623 class_format_error("Invalid method signature");



31 #include "classfile/systemDictionary.hpp" 32 #include "classfile/verifier.hpp" 33 #include "classfile/vmSymbols.hpp" 34 #include "interpreter/bytecodes.hpp" 35 #include "interpreter/bytecodeStream.hpp" 36 #include "memory/oopFactory.hpp" 37 #include "memory/resourceArea.hpp" 38 #include "oops/instanceKlass.hpp" 39 #include "oops/oop.inline.hpp" 40 #include "oops/typeArrayOop.hpp" 41 #include "prims/jvm.h" 42 #include "runtime/fieldDescriptor.hpp" 43 #include "runtime/handles.inline.hpp" 44 #include "runtime/interfaceSupport.hpp" 45 #include "runtime/javaCalls.hpp" 46 #include "runtime/orderAccess.inline.hpp" 47 #include "runtime/os.hpp" 48 #include "runtime/thread.hpp" 49 #include "services/threadService.hpp" 50 #include "utilities/bytes.hpp" 51 #include "logging/log.hpp" 52 53 #define NOFAILOVER_MAJOR_VERSION 51 54 #define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION 51 55 #define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION 52 56 57 // Access to external entry for VerifyClassCodes - old byte code verifier 58 59 extern "C" { 60 typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint); 61 typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv , jclass, char , jint, jint); 62 } 63 64 static void volatile _verify_byte_codes_fn = NULL; 65 66 static volatile jint _is_new_verify_byte_codes_fn = (jint) true; 67 68 static void verify_byte_codes_fn() { 69 if (_verify_byte_codes_fn == NULL) { 70 void *lib_handle = os::native_java_library(); 71 void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion");


95 // verifyRemote 96 (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted); 97 return !need_verify; 98 } 99 100 void Verifier::trace_class_resolution(Klass* resolve_class, InstanceKlass* verify_class) { 101 assert(verify_class != NULL, "Unexpected null verify_class"); 102 ResourceMark rm; 103 Symbol* s = verify_class->source_file_name(); 104 const char* source_file = (s != NULL ? s->as_C_string() : NULL); 105 const char* verify = verify_class->external_name(); 106 const char* resolve = resolve_class->external_name(); 107 // print in a single call to reduce interleaving between threads 108 if (source_file != NULL) { 109 tty->print("RESOLVE %s %s %s (verification)\n", verify, resolve, source_file); 110 } else { 111 tty->print("RESOLVE %s %s (verification)\n", verify, resolve); 112 } 113 } 114 115 // Prints the end-verification message to the appropriate output. 116 void Verifier::log_end_verification(outputStream* st, const char* klassName, Symbol* exception_name, TRAPS) { 117 if (HAS_PENDING_EXCEPTION) { 118 st->print("Verification for %s has", klassName); 119 st->print_cr(" exception pending %s ", 120 PENDING_EXCEPTION->klass()->external_name()); 121 } else if (exception_name != NULL) { 122 st->print_cr("Verification for %s failed", klassName); 123 } 124 st->print_cr("End class verification for: %s", klassName); 125 } 126 127 bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) { 128 HandleMark hm; 129 ResourceMark rm(THREAD); 130 131 // Eagerly allocate the identity hash code for a klass. This is a fallout 132 // from 6320749 and 8059924: hash code generator is not supposed to be called 133 // during the safepoint, but it allows to sneak the hashcode in during 134 // verification. Without this eager hashcode generation, we may end up 135 // installing the hashcode during some other operation, which may be at 136 // safepoint -- blowing up the checks. It was previously done as the side 137 // effect (sic!) for external_name(), but instead of doing that, we opt to 138 // explicitly push the hashcode in here. This is signify the following block 139 // is IMPORTANT: 140 if (klass->java_mirror() != NULL) { 141 klass->java_mirror()->identity_hash(); 142 } 143 144 if (!is_eligible_for_verification(klass, should_verify_class)) { 145 return true; 146 }


151 PerfClassTraceTime timer(ClassLoader::perf_class_verify_time(), 152 ClassLoader::perf_class_verify_selftime(), 153 ClassLoader::perf_classes_verified(), 154 jt->get_thread_stat()->perf_recursion_counts_addr(), 155 jt->get_thread_stat()->perf_timers_addr(), 156 PerfClassTraceTime::CLASS_VERIFY); 157 158 // If the class should be verified, first see if we can use the split 159 // verifier. If not, or if verification fails and FailOverToOldVerifier 160 // is set, then call the inference verifier. 161 162 Symbol* exception_name = NULL; 163 const size_t message_buffer_len = klass->name()->utf8_length() + 1024; 164 char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len); 165 char* exception_message = message_buffer; 166 167 const char* klassName = klass->external_name(); 168 bool can_failover = FailOverToOldVerifier && 169 klass->major_version() < NOFAILOVER_MAJOR_VERSION; 170
171 log_info(classinit)("Start class verification for: %s", klassName);

172 if (klass->major_version() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) { 173 ClassVerifier split_verifier(klass, THREAD); 174 split_verifier.verify_class(THREAD); 175 exception_name = split_verifier.result(); 176 if (can_failover && !HAS_PENDING_EXCEPTION && 177 (exception_name == vmSymbols::java_lang_VerifyError() || 178 exception_name == vmSymbols::java_lang_ClassFormatError())) { 179 if (VerboseVerification) { 180 tty->print_cr("Fail over class verification to old verifier for: %s", klassName);

181 } 182 log_info(classinit)("Fail over class verification to old verifier for: %s", klassName); 183 exception_name = inference_verify( 184 klass, message_buffer, message_buffer_len, THREAD); 185 } 186 if (exception_name != NULL) { 187 exception_message = split_verifier.exception_message(); 188 } 189 } else { 190 exception_name = inference_verify( 191 klass, message_buffer, message_buffer_len, THREAD); 192 } 193 194 if (log_is_enabled(Info, classinit)){ 195 log_end_verification(LogHandle(classinit)::info_stream(), klassName, exception_name, THREAD);

196 } 197 if (VerboseVerification){ 198 log_end_verification(tty, klassName, exception_name, THREAD); 199 } 200 201 if (HAS_PENDING_EXCEPTION) { 202 return false; // use the existing exception 203 } else if (exception_name == NULL) { 204 return true; // verifcation succeeded 205 } else { // VerifyError or ClassFormatError to be created and thrown 206 ResourceMark rm(THREAD); 207 instanceKlassHandle kls = 208 SystemDictionary::resolve_or_fail(exception_name, true, CHECK_false); 209 if (TraceClassResolution) { 210 Verifier::trace_class_resolution(kls(), klass()); 211 } 212 213 while (!kls.is_null()) { 214 if (kls == klass) { 215 // If the class being verified is the exception we're creating 216 // or one of it's superclasses, we're in trouble and are going 217 // to infinitely recurse when we try to initialize the exception. 218 // So bail out here by throwing the preallocated VM error.


588 _klass->external_name()); 589 } 590 591 Array<Method*>* methods = _klass->methods(); 592 int num_methods = methods->length(); 593 594 for (int index = 0; index < num_methods; index++) { 595 // Check for recursive re-verification before each method. 596 if (was_recursively_verified()) return; 597 598 Method* m = methods->at(index); 599 if (m->is_native() || m->is_abstract() || m->is_overpass()) { 600 // If m is native or abstract, skip it. It is checked in class file 601 // parser that methods do not override a final method. Overpass methods 602 // are trusted since the VM generates them. 603 continue; 604 } 605 verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this)); 606 } 607 608 if (was_recursively_verified()){ 609 if (VerboseVerification){
610 tty->print_cr("Recursive verification detected for: %s", 611 _klass->external_name()); 612 } 613 log_info(classinit)("Recursive verification detected for: %s", 614 _klass->external_name()); 615 } 616 } 617 618 void ClassVerifier::verify_method(const methodHandle& m, TRAPS) { 619 HandleMark hm(THREAD); 620 _method = m; // initialize _method 621 if (VerboseVerification) { 622 tty->print_cr("Verifying method %s", m->name_and_sig_as_C_string()); 623 } 624 625 // For clang, the only good constant format string is a literal constant format string. 626 #define bad_type_msg "Bad type on operand stack in %s" 627 628 int32_t max_stack = m->verifier_max_stack(); 629 int32_t max_locals = m->max_locals(); 630 constantPoolHandle cp(THREAD, m->constants()); 631 632 if (!SignatureVerifier::is_valid_method_signature(m->signature())) { 633 class_format_error("Invalid method signature");