593 |
593 |
594 VerificationType ClassVerifier::object_type() const { |
594 VerificationType ClassVerifier::object_type() const { |
595 return VerificationType::reference_type(vmSymbols::java_lang_Object()); |
595 return VerificationType::reference_type(vmSymbols::java_lang_Object()); |
596 } |
596 } |
597 |
597 |
598 TypeOrigin ClassVerifier::ref_ctx(const char* sig, TRAPS) { |
598 TypeOrigin ClassVerifier::ref_ctx(const char* sig) { |
599 VerificationType vt = VerificationType::reference_type( |
599 VerificationType vt = VerificationType::reference_type( |
600 create_temporary_symbol(sig, (int)strlen(sig), THREAD)); |
600 create_temporary_symbol(sig, (int)strlen(sig))); |
601 return TypeOrigin::implicit(vt); |
601 return TypeOrigin::implicit(vt); |
602 } |
602 } |
603 |
603 |
604 void ClassVerifier::verify_class(TRAPS) { |
604 void ClassVerifier::verify_class(TRAPS) { |
605 log_info(verification)("Verifying class %s with new format", _klass->external_name()); |
605 log_info(verification)("Verifying class %s with new format", _klass->external_name()); |
645 int sig_i = 0; |
645 int sig_i = 0; |
646 GrowableArray<VerificationType>* verif_types = sig_verif_types->sig_verif_types(); |
646 GrowableArray<VerificationType>* verif_types = sig_verif_types->sig_verif_types(); |
647 |
647 |
648 // Translate the signature arguments into verification types. |
648 // Translate the signature arguments into verification types. |
649 while (!sig_stream.at_return_type()) { |
649 while (!sig_stream.at_return_type()) { |
650 int n = change_sig_to_verificationType(&sig_stream, sig_type, CHECK_VERIFY(this)); |
650 int n = change_sig_to_verificationType(&sig_stream, sig_type); |
651 assert(n <= 2, "Unexpected signature type"); |
651 assert(n <= 2, "Unexpected signature type"); |
652 |
652 |
653 // Store verification type(s). Longs and Doubles each have two verificationTypes. |
653 // Store verification type(s). Longs and Doubles each have two verificationTypes. |
654 for (int x = 0; x < n; x++) { |
654 for (int x = 0; x < n; x++) { |
655 verif_types->push(sig_type[x]); |
655 verif_types->push(sig_type[x]); |
662 // be compared with sig_verify_types' length to see if there is a return type. |
662 // be compared with sig_verify_types' length to see if there is a return type. |
663 sig_verif_types->set_num_args(sig_i); |
663 sig_verif_types->set_num_args(sig_i); |
664 |
664 |
665 // Store verification type(s) for the return type, if there is one. |
665 // Store verification type(s) for the return type, if there is one. |
666 if (sig_stream.type() != T_VOID) { |
666 if (sig_stream.type() != T_VOID) { |
667 int n = change_sig_to_verificationType(&sig_stream, sig_type, CHECK_VERIFY(this)); |
667 int n = change_sig_to_verificationType(&sig_stream, sig_type); |
668 assert(n <= 2, "Unexpected signature return type"); |
668 assert(n <= 2, "Unexpected signature return type"); |
669 for (int y = 0; y < n; y++) { |
669 for (int y = 0; y < n; y++) { |
670 verif_types->push(sig_type[y]); |
670 verif_types->push(sig_type[y]); |
671 } |
671 } |
672 } |
672 } |
923 VerificationType::integer_type(), CHECK_VERIFY(this)); |
923 VerificationType::integer_type(), CHECK_VERIFY(this)); |
924 atype = current_frame.pop_stack( |
924 atype = current_frame.pop_stack( |
925 VerificationType::reference_check(), CHECK_VERIFY(this)); |
925 VerificationType::reference_check(), CHECK_VERIFY(this)); |
926 if (!atype.is_int_array()) { |
926 if (!atype.is_int_array()) { |
927 verify_error(ErrorContext::bad_type(bci, |
927 verify_error(ErrorContext::bad_type(bci, |
928 current_frame.stack_top_ctx(), ref_ctx("[I", THREAD)), |
928 current_frame.stack_top_ctx(), ref_ctx("[I")), |
929 bad_type_msg, "iaload"); |
929 bad_type_msg, "iaload"); |
930 return; |
930 return; |
931 } |
931 } |
932 current_frame.push_stack( |
932 current_frame.push_stack( |
933 VerificationType::integer_type(), CHECK_VERIFY(this)); |
933 VerificationType::integer_type(), CHECK_VERIFY(this)); |
951 VerificationType::integer_type(), CHECK_VERIFY(this)); |
951 VerificationType::integer_type(), CHECK_VERIFY(this)); |
952 atype = current_frame.pop_stack( |
952 atype = current_frame.pop_stack( |
953 VerificationType::reference_check(), CHECK_VERIFY(this)); |
953 VerificationType::reference_check(), CHECK_VERIFY(this)); |
954 if (!atype.is_char_array()) { |
954 if (!atype.is_char_array()) { |
955 verify_error(ErrorContext::bad_type(bci, |
955 verify_error(ErrorContext::bad_type(bci, |
956 current_frame.stack_top_ctx(), ref_ctx("[C", THREAD)), |
956 current_frame.stack_top_ctx(), ref_ctx("[C")), |
957 bad_type_msg, "caload"); |
957 bad_type_msg, "caload"); |
958 return; |
958 return; |
959 } |
959 } |
960 current_frame.push_stack( |
960 current_frame.push_stack( |
961 VerificationType::integer_type(), CHECK_VERIFY(this)); |
961 VerificationType::integer_type(), CHECK_VERIFY(this)); |
965 VerificationType::integer_type(), CHECK_VERIFY(this)); |
965 VerificationType::integer_type(), CHECK_VERIFY(this)); |
966 atype = current_frame.pop_stack( |
966 atype = current_frame.pop_stack( |
967 VerificationType::reference_check(), CHECK_VERIFY(this)); |
967 VerificationType::reference_check(), CHECK_VERIFY(this)); |
968 if (!atype.is_short_array()) { |
968 if (!atype.is_short_array()) { |
969 verify_error(ErrorContext::bad_type(bci, |
969 verify_error(ErrorContext::bad_type(bci, |
970 current_frame.stack_top_ctx(), ref_ctx("[S", THREAD)), |
970 current_frame.stack_top_ctx(), ref_ctx("[S")), |
971 bad_type_msg, "saload"); |
971 bad_type_msg, "saload"); |
972 return; |
972 return; |
973 } |
973 } |
974 current_frame.push_stack( |
974 current_frame.push_stack( |
975 VerificationType::integer_type(), CHECK_VERIFY(this)); |
975 VerificationType::integer_type(), CHECK_VERIFY(this)); |
979 VerificationType::integer_type(), CHECK_VERIFY(this)); |
979 VerificationType::integer_type(), CHECK_VERIFY(this)); |
980 atype = current_frame.pop_stack( |
980 atype = current_frame.pop_stack( |
981 VerificationType::reference_check(), CHECK_VERIFY(this)); |
981 VerificationType::reference_check(), CHECK_VERIFY(this)); |
982 if (!atype.is_long_array()) { |
982 if (!atype.is_long_array()) { |
983 verify_error(ErrorContext::bad_type(bci, |
983 verify_error(ErrorContext::bad_type(bci, |
984 current_frame.stack_top_ctx(), ref_ctx("[J", THREAD)), |
984 current_frame.stack_top_ctx(), ref_ctx("[J")), |
985 bad_type_msg, "laload"); |
985 bad_type_msg, "laload"); |
986 return; |
986 return; |
987 } |
987 } |
988 current_frame.push_stack_2( |
988 current_frame.push_stack_2( |
989 VerificationType::long_type(), |
989 VerificationType::long_type(), |
994 VerificationType::integer_type(), CHECK_VERIFY(this)); |
994 VerificationType::integer_type(), CHECK_VERIFY(this)); |
995 atype = current_frame.pop_stack( |
995 atype = current_frame.pop_stack( |
996 VerificationType::reference_check(), CHECK_VERIFY(this)); |
996 VerificationType::reference_check(), CHECK_VERIFY(this)); |
997 if (!atype.is_float_array()) { |
997 if (!atype.is_float_array()) { |
998 verify_error(ErrorContext::bad_type(bci, |
998 verify_error(ErrorContext::bad_type(bci, |
999 current_frame.stack_top_ctx(), ref_ctx("[F", THREAD)), |
999 current_frame.stack_top_ctx(), ref_ctx("[F")), |
1000 bad_type_msg, "faload"); |
1000 bad_type_msg, "faload"); |
1001 return; |
1001 return; |
1002 } |
1002 } |
1003 current_frame.push_stack( |
1003 current_frame.push_stack( |
1004 VerificationType::float_type(), CHECK_VERIFY(this)); |
1004 VerificationType::float_type(), CHECK_VERIFY(this)); |
1008 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1008 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1009 atype = current_frame.pop_stack( |
1009 atype = current_frame.pop_stack( |
1010 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1010 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1011 if (!atype.is_double_array()) { |
1011 if (!atype.is_double_array()) { |
1012 verify_error(ErrorContext::bad_type(bci, |
1012 verify_error(ErrorContext::bad_type(bci, |
1013 current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)), |
1013 current_frame.stack_top_ctx(), ref_ctx("[D")), |
1014 bad_type_msg, "daload"); |
1014 bad_type_msg, "daload"); |
1015 return; |
1015 return; |
1016 } |
1016 } |
1017 current_frame.push_stack_2( |
1017 current_frame.push_stack_2( |
1018 VerificationType::double_type(), |
1018 VerificationType::double_type(), |
1097 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1097 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1098 atype = current_frame.pop_stack( |
1098 atype = current_frame.pop_stack( |
1099 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1099 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1100 if (!atype.is_int_array()) { |
1100 if (!atype.is_int_array()) { |
1101 verify_error(ErrorContext::bad_type(bci, |
1101 verify_error(ErrorContext::bad_type(bci, |
1102 current_frame.stack_top_ctx(), ref_ctx("[I", THREAD)), |
1102 current_frame.stack_top_ctx(), ref_ctx("[I")), |
1103 bad_type_msg, "iastore"); |
1103 bad_type_msg, "iastore"); |
1104 return; |
1104 return; |
1105 } |
1105 } |
1106 no_control_flow = false; break; |
1106 no_control_flow = false; break; |
1107 case Bytecodes::_bastore : |
1107 case Bytecodes::_bastore : |
1125 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1125 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1126 atype = current_frame.pop_stack( |
1126 atype = current_frame.pop_stack( |
1127 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1127 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1128 if (!atype.is_char_array()) { |
1128 if (!atype.is_char_array()) { |
1129 verify_error(ErrorContext::bad_type(bci, |
1129 verify_error(ErrorContext::bad_type(bci, |
1130 current_frame.stack_top_ctx(), ref_ctx("[C", THREAD)), |
1130 current_frame.stack_top_ctx(), ref_ctx("[C")), |
1131 bad_type_msg, "castore"); |
1131 bad_type_msg, "castore"); |
1132 return; |
1132 return; |
1133 } |
1133 } |
1134 no_control_flow = false; break; |
1134 no_control_flow = false; break; |
1135 case Bytecodes::_sastore : |
1135 case Bytecodes::_sastore : |
1139 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1139 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1140 atype = current_frame.pop_stack( |
1140 atype = current_frame.pop_stack( |
1141 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1141 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1142 if (!atype.is_short_array()) { |
1142 if (!atype.is_short_array()) { |
1143 verify_error(ErrorContext::bad_type(bci, |
1143 verify_error(ErrorContext::bad_type(bci, |
1144 current_frame.stack_top_ctx(), ref_ctx("[S", THREAD)), |
1144 current_frame.stack_top_ctx(), ref_ctx("[S")), |
1145 bad_type_msg, "sastore"); |
1145 bad_type_msg, "sastore"); |
1146 return; |
1146 return; |
1147 } |
1147 } |
1148 no_control_flow = false; break; |
1148 no_control_flow = false; break; |
1149 case Bytecodes::_lastore : |
1149 case Bytecodes::_lastore : |
1154 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1154 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1155 atype = current_frame.pop_stack( |
1155 atype = current_frame.pop_stack( |
1156 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1156 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1157 if (!atype.is_long_array()) { |
1157 if (!atype.is_long_array()) { |
1158 verify_error(ErrorContext::bad_type(bci, |
1158 verify_error(ErrorContext::bad_type(bci, |
1159 current_frame.stack_top_ctx(), ref_ctx("[J", THREAD)), |
1159 current_frame.stack_top_ctx(), ref_ctx("[J")), |
1160 bad_type_msg, "lastore"); |
1160 bad_type_msg, "lastore"); |
1161 return; |
1161 return; |
1162 } |
1162 } |
1163 no_control_flow = false; break; |
1163 no_control_flow = false; break; |
1164 case Bytecodes::_fastore : |
1164 case Bytecodes::_fastore : |
1168 (VerificationType::integer_type(), CHECK_VERIFY(this)); |
1168 (VerificationType::integer_type(), CHECK_VERIFY(this)); |
1169 atype = current_frame.pop_stack( |
1169 atype = current_frame.pop_stack( |
1170 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1170 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1171 if (!atype.is_float_array()) { |
1171 if (!atype.is_float_array()) { |
1172 verify_error(ErrorContext::bad_type(bci, |
1172 verify_error(ErrorContext::bad_type(bci, |
1173 current_frame.stack_top_ctx(), ref_ctx("[F", THREAD)), |
1173 current_frame.stack_top_ctx(), ref_ctx("[F")), |
1174 bad_type_msg, "fastore"); |
1174 bad_type_msg, "fastore"); |
1175 return; |
1175 return; |
1176 } |
1176 } |
1177 no_control_flow = false; break; |
1177 no_control_flow = false; break; |
1178 case Bytecodes::_dastore : |
1178 case Bytecodes::_dastore : |
1183 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1183 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1184 atype = current_frame.pop_stack( |
1184 atype = current_frame.pop_stack( |
1185 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1185 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1186 if (!atype.is_double_array()) { |
1186 if (!atype.is_double_array()) { |
1187 verify_error(ErrorContext::bad_type(bci, |
1187 verify_error(ErrorContext::bad_type(bci, |
1188 current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)), |
1188 current_frame.stack_top_ctx(), ref_ctx("[D")), |
1189 bad_type_msg, "dastore"); |
1189 bad_type_msg, "dastore"); |
1190 return; |
1190 return; |
1191 } |
1191 } |
1192 no_control_flow = false; break; |
1192 no_control_flow = false; break; |
1193 case Bytecodes::_aastore : |
1193 case Bytecodes::_aastore : |
2181 assert(sizeof(VerificationType) == sizeof(uintptr_t), |
2181 assert(sizeof(VerificationType) == sizeof(uintptr_t), |
2182 "buffer type must match VerificationType size"); |
2182 "buffer type must match VerificationType size"); |
2183 uintptr_t constant_type_buffer[2]; |
2183 uintptr_t constant_type_buffer[2]; |
2184 VerificationType* v_constant_type = (VerificationType*)constant_type_buffer; |
2184 VerificationType* v_constant_type = (VerificationType*)constant_type_buffer; |
2185 SignatureStream sig_stream(constant_type, false); |
2185 SignatureStream sig_stream(constant_type, false); |
2186 int n = change_sig_to_verificationType( |
2186 int n = change_sig_to_verificationType(&sig_stream, v_constant_type); |
2187 &sig_stream, v_constant_type, CHECK_VERIFY(this)); |
|
2188 int opcode_n = (opcode == Bytecodes::_ldc2_w ? 2 : 1); |
2187 int opcode_n = (opcode == Bytecodes::_ldc2_w ? 2 : 1); |
2189 if (n != opcode_n) { |
2188 if (n != opcode_n) { |
2190 // wrong kind of ldc; reverify against updated type mask |
2189 // wrong kind of ldc; reverify against updated type mask |
2191 types &= ~(1 << JVM_CONSTANT_Dynamic); |
2190 types &= ~(1 << JVM_CONSTANT_Dynamic); |
2192 verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this)); |
2191 verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this)); |
2323 // stack allocating it. Plus it would run constructors. This shows up |
2322 // stack allocating it. Plus it would run constructors. This shows up |
2324 // in performance profiles. |
2323 // in performance profiles. |
2325 |
2324 |
2326 SignatureStream sig_stream(field_sig, false); |
2325 SignatureStream sig_stream(field_sig, false); |
2327 VerificationType stack_object_type; |
2326 VerificationType stack_object_type; |
2328 int n = change_sig_to_verificationType( |
2327 int n = change_sig_to_verificationType(&sig_stream, field_type); |
2329 &sig_stream, field_type, CHECK_VERIFY(this)); |
|
2330 u2 bci = bcs->bci(); |
2328 u2 bci = bcs->bci(); |
2331 bool is_assignable; |
2329 bool is_assignable; |
2332 switch (bcs->raw_code()) { |
2330 switch (bcs->raw_code()) { |
2333 case Bytecodes::_getstatic: { |
2331 case Bytecodes::_getstatic: { |
2334 for (int i = 0; i < n; i++) { |
2332 for (int i = 0; i < n; i++) { |
3000 verify_error(ErrorContext::bad_code(bci), "Illegal newarray instruction"); |
2998 verify_error(ErrorContext::bad_code(bci), "Illegal newarray instruction"); |
3001 return VerificationType::bogus_type(); |
2999 return VerificationType::bogus_type(); |
3002 } |
3000 } |
3003 |
3001 |
3004 // from_bt[index] contains the array signature which has a length of 2 |
3002 // from_bt[index] contains the array signature which has a length of 2 |
3005 Symbol* sig = create_temporary_symbol( |
3003 Symbol* sig = create_temporary_symbol(from_bt[index], 2); |
3006 from_bt[index], 2, CHECK_(VerificationType::bogus_type())); |
|
3007 return VerificationType::reference_type(sig); |
3004 return VerificationType::reference_type(sig); |
3008 } |
3005 } |
3009 |
3006 |
3010 void ClassVerifier::verify_anewarray( |
3007 void ClassVerifier::verify_anewarray( |
3011 u2 bci, u2 index, const constantPoolHandle& cp, |
3008 u2 bci, u2 index, const constantPoolHandle& cp, |
3039 length = (int)strlen(component_name) + 3; |
3036 length = (int)strlen(component_name) + 3; |
3040 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length + 1); |
3037 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length + 1); |
3041 int n = os::snprintf(arr_sig_str, length + 1, "[L%s;", component_name); |
3038 int n = os::snprintf(arr_sig_str, length + 1, "[L%s;", component_name); |
3042 assert(n == length, "Unexpected number of characters in string"); |
3039 assert(n == length, "Unexpected number of characters in string"); |
3043 } |
3040 } |
3044 Symbol* arr_sig = create_temporary_symbol( |
3041 Symbol* arr_sig = create_temporary_symbol(arr_sig_str, length); |
3045 arr_sig_str, length, CHECK_VERIFY(this)); |
|
3046 VerificationType new_array_type = VerificationType::reference_type(arr_sig); |
3042 VerificationType new_array_type = VerificationType::reference_type(arr_sig); |
3047 current_frame->push_stack(new_array_type, CHECK_VERIFY(this)); |
3043 current_frame->push_stack(new_array_type, CHECK_VERIFY(this)); |
3048 } |
3044 } |
3049 |
3045 |
3050 void ClassVerifier::verify_iload(u2 index, StackMapFrame* current_frame, TRAPS) { |
3046 void ClassVerifier::verify_iload(u2 index, StackMapFrame* current_frame, TRAPS) { |
3148 |
3144 |
3149 // The verifier creates symbols which are substrings of Symbols. |
3145 // The verifier creates symbols which are substrings of Symbols. |
3150 // These are stored in the verifier until the end of verification so that |
3146 // These are stored in the verifier until the end of verification so that |
3151 // they can be reference counted. |
3147 // they can be reference counted. |
3152 Symbol* ClassVerifier::create_temporary_symbol(const Symbol *s, int begin, |
3148 Symbol* ClassVerifier::create_temporary_symbol(const Symbol *s, int begin, |
3153 int end, TRAPS) { |
3149 int end) { |
3154 const char* name = (const char*)s->base() + begin; |
3150 const char* name = (const char*)s->base() + begin; |
3155 int length = end - begin; |
3151 int length = end - begin; |
3156 return create_temporary_symbol(name, length, CHECK_NULL); |
3152 return create_temporary_symbol(name, length); |
3157 } |
3153 } |
3158 |
3154 |
3159 Symbol* ClassVerifier::create_temporary_symbol(const char *name, int length, TRAPS) { |
3155 Symbol* ClassVerifier::create_temporary_symbol(const char *name, int length) { |
3160 // Quick deduplication check |
3156 // Quick deduplication check |
3161 if (_previous_symbol != NULL && _previous_symbol->equals(name, length)) { |
3157 if (_previous_symbol != NULL && _previous_symbol->equals(name, length)) { |
3162 return _previous_symbol; |
3158 return _previous_symbol; |
3163 } |
3159 } |
3164 Symbol* sym = SymbolTable::new_symbol(name, length, CHECK_NULL); |
3160 Symbol* sym = SymbolTable::new_symbol(name, length); |
3165 if (!sym->is_permanent()) { |
3161 if (!sym->is_permanent()) { |
3166 if (_symbols == NULL) { |
3162 if (_symbols == NULL) { |
3167 _symbols = new GrowableArray<Symbol*>(50, 0, NULL); |
3163 _symbols = new GrowableArray<Symbol*>(50, 0, NULL); |
3168 } |
3164 } |
3169 _symbols->push(sym); |
3165 _symbols->push(sym); |